Methods
Public Instance methods
cast_from(object)

Cast on object from another

  String.cast_from(1234) => "1234"
# File lib/facets/more/typecast.rb, line 121
  def cast_from(object)
    method_to = "to_#{self.name.methodize}".to_sym
    if object.respond_to? method_to
      retval = object.send(method_to)
      return retval
    end

    method_from = "from_#{object.class.name.methodize}".to_sym
    if respond_to? method_from
      retval = send(method_from, object)
      return retval
    end

    raise TypeCastException, "TypeCasting from #{object.class.name} to #{self.name} not supported"
  end
cast_to(klass)

Cast an object to another

   1234.cast_to(String)  => "1234"
# File lib/facets/more/typecast.rb, line 113
  def cast_to(klass)
    klass.cast_from(self)
  end
inheritor( key, obj, op=nil )

Create an inheritor "class attribute".

# File lib/facets/more/inheritor.rb, line 55
  def inheritor( key, obj, op=nil )

    # inhertiance operator
    op = op ? op.to_sym : :add

    # inheritor store a this level
    instance_variable_set("@#{key}", obj)

    #base = self
    deflambda = lambda do

      define_method( key ) do
        defined?(super) ? super.__send__(op,obj) : obj.dup
      end

      define_method( "#{key}!" ) do
        instance_variable_get("@#{key}") || inheritor( key, obj.class.new, op )
        #if instance_variables.include?("@#{key}")
        #  instance_variable_get("@#{key}")
        #else
        #  if self != base
        #    inheritor( key, obj.class.new, op )
        #  end
        #end
      end
    end

    # TODO This is an issue if you try to include a module
    # into Module or Class itself. How to fix?

    # if the object is a module (not a class or other object)
    if self == Class or self == Module
      class_eval &deflambda
    elsif is_a?(Class)
      (class << self; self; end).class_eval &deflambda
    elsif is_a?(Module)
      #class_inherit &deflambda
      extend class_extension( &deflambda )
    else # other Object
      (class << self; self; end).class_eval &deflambda
    end

    obj
  end
null?()
# File lib/facets/more/nullclass.rb, line 52
  def null?
    false
  end
restore_snapshot(snap)
# File lib/facets/more/snapshot.rb, line 131
  def restore_snapshot(snap)
    instance_variables.each do |iv|
      instance_variable_set(iv, snap[iv])
    end
  end
send_task( name )
# File lib/facets/more/taskable.rb, line 247
  def send_task( name )
    (class << self; self; end).instance_task( name )
  end
take_snapshot()
# File lib/facets/more/snapshot.rb, line 123
  def take_snapshot
    snap = Hash.new
    instance_variables.each do |iv|
      snap[iv] = instance_variable_get(iv)
    end
    snap
  end
to_json(*)

Converts this object to a string (calling to_s), converts it to a JSON string, and returns the result. This is a fallback, if no special method to_json was defined for some object. state is a JSON::State object, that can also be used to configure the produced JSON string output further.

# File lib/facets/more/json.rb, line 490
  def to_json(*) to_s.to_json end