Sha256: 918ee37c4845dac5fac8d08afd2f234df72ff04b0dc9f58770de8abb1bd2a4f8

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Extensions #:nodoc:
    module Object #:nodoc:

      # This module behaves like the master jedi.
      module Yoda #:nodoc:

        # Do or do not, there is no try. -- Yoda.
        #
        # @example Do or do not.
        #   object.do_or_do_not(:use, "The Force")
        #
        # @param [ String, Symbol ] name The method name.
        # @param [ Array ] *args The arguments.
        #
        # @return [ Object, nil ] The result of the method call or nil if the
        #   method does not exist.
        #
        # @since 2.0.0.rc.1
        def do_or_do_not(name, *args)
          respond_to?(name) ? send(name, *args) : nil
        end

        # You must unlearn what you have learned. -- Yoda
        #
        # @example You must perform this execution.
        #   object.you_must(:use, "The Force")
        #
        # @param [ String, Symbol ] name The method name.
        # @param [ Array ] *args The arguments.
        #
        # @return [ Object, nil ] The result of the method call or nil if the
        #   method does not exist. Nil if the object is frozen.
        #
        # @since 2.2.1
        def you_must(name, *args)
          frozen? ? nil : do_or_do_not(name, *args)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mongoid-2.2.6 lib/mongoid/extensions/object/yoda.rb
mongoid-2.2.5 lib/mongoid/extensions/object/yoda.rb
mongoid-2.2.4 lib/mongoid/extensions/object/yoda.rb
mongoid-2.2.3 lib/mongoid/extensions/object/yoda.rb
mongoid-2.3.1 lib/mongoid/extensions/object/yoda.rb
mongoid-2.3.0 lib/mongoid/extensions/object/yoda.rb
mongoid-2.2.2 lib/mongoid/extensions/object/yoda.rb
mongoid-2.2.1 lib/mongoid/extensions/object/yoda.rb