Class: Object

Class | Object
In: | lib/extlib/blank.rb lib/extlib/object.rb
Parent: | Object

### Methods

blank? full_const_get full_const_set in? instance_variable_defined? make_module meta_class quacks_like? try_call try_dup

### Public Instance methods

blank?()

Returns true if the object is nil or empty (if applicable)

      [].blank?         #=>  true
      [1].blank?        #=>  false
      [nil].blank?      #=>  false

@return [TrueClass, FalseClass]

@api public

full_const_get(name)

@param name<String> The name of the constant to get, e.g. "Merb::Router".

@return <Object> The constant corresponding to the name.

full_const_set(name, value)

@param name<String> The name of the constant to get, e.g. "Merb::Router". @param value<Object> The value to assign to the constant.

@return <Object> The constant corresponding to the name.

in?(arrayish,*more)

@param arrayish<include?> Container to check, to see if it includes the object.

@param *more<Array>: | additional args, will be flattened into arrayish

@return <TrueClass, FalseClass>

      True if the object is included in arrayish (+ more)

@example 1.in?([1,2,3]) #=> true @example 1.in?(1,2,3) #=> true

instance_variable_defined?(variable)
make_module(str)

Defines module from a string name (e.g. Foo::Bar::Baz) If module already exists, no exception raised.

@param name<String> The name of the full module name to make

@return <NilClass>

meta_class()

Extracts the singleton class, so that metaprogramming can be done on it.

@return <Class> The meta class.

@example [Setup]

      class MyString < String; end

      MyString.instance_eval do
        define_method :foo do
          puts self
        end
      end

      MyString.meta_class.instance_eval do
        define_method :bar do
          puts self
        end
      end

      def String.add_meta_var(var)
        self.meta_class.instance_eval do
          define_method var do
            puts "HELLO"
          end
        end
      end

@example

      MyString.new("Hello").foo #=> "Hello"

@example

      MyString.new("Hello").bar
        #=> NoMethodError: undefined method `bar' for "Hello":MyString

@example

      MyString.foo
        #=> NoMethodError: undefined method `foo' for MyString:Class

@example

      MyString.bar
        #=> MyString

@example

      String.bar
        #=> NoMethodError: undefined method `bar' for String:Class

@example

      MyString.add_meta_var(:x)
      MyString.x #=> HELLO

@details [Description of Examples]

      As you can see, using #meta_class allows you to execute code (and here,
      define a method) on the metaclass itself. It also allows you to define
      class methods that can be run on subclasses, and then be able to execute
      code on the metaclass of the subclass (here MyString).

      In this case, we were able to define a class method (add_meta_var) on
      String that was executable by the MyString subclass. It was then able to
      define a method on the subclass by adding it to the MyString metaclass.

      For more information, you can check out _why's excellent article at:
      http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html

quacks_like?(duck)

@param duck<Symbol, Class, Array> The thing to compare the object to.

@note

      The behavior of the method depends on the type of duck as follows:
      Symbol:: Check whether the object respond_to?(duck).
      Class:: Check whether the object is_a?(duck).
      Array::
        Check whether the object quacks_like? at least one of the options in the
        array.

@return <TrueClass, FalseClass>

      True if the object quacks like duck.

try_call(*args)

If receiver is callable, calls it and returns result. If not, just returns receiver itself

@return <Object>

try_dup()

Override this in a child if it cannot be dup‘ed

@return <Object>

[Validate]