Object
Coerce Object values
Return if the value was successfuly coerced
@example when coercion was successful
coercer[String].coerced?(1) # => true
@example when coercion was NOT successful
coercer[String].coerced?("foo") # => false
@return [TrueClass,FalseClass]
@api public
# File lib/coercible/coercer/object.rb, line 136 def coerced?(value) value.kind_of?(self.class.primitive) end
Inspect the coercer object
@example
coercer[Object].inspect # => "<Coercer::Object primitive=Object>"
@return [String]
@api public
# File lib/coercible/coercer/object.rb, line 40 def inspect "#<#{self.class} primitive=#{self.class.primitive}>" end
Create an Array from any Object
@example with an object that does not respond to to_a or to_ary
coercer[Object].to_array(value) # => [ value ]
@example with an object that responds to to_a
coercer[Object].to_array(Set[ value ]) # => [ value ]
@example with n object that responds to to_ary
coercer[Object].to_array([ value ]) # => [ value ]
@param [to_a,to_ary,Object] value @param [to_a,to_ary,Object] value
@return [Array]
@api public
# File lib/coercible/coercer/object.rb, line 61 def to_array(value) Array(value) end
Create a Hash from the Object if possible
@example with a coercible object
coercer[Object].to_hash(key => value) # => { key => value }
@example with an object that is not coercible
coercer[Object].to_hash(value) # => value
@param [to_hash, Object] value
@return [Hash]
returns a Hash when the object can be coerced
@return [Object]
returns the value when the object cannot be coerced
@api public
# File lib/coercible/coercer/object.rb, line 81 def to_hash(value) coerce_with_method(value, :to_hash, __method__) end
Create an Integer from the Object if possible
@example with a coercible object
coercer[Object].to_integer(1) # => 1
@example with an object that is not coercible
coercer[Object].to_integer(value) # => value
@param [to_int, Object] value
@return [Integer]
returns an Integer when the object can be coerced
@return [Object]
returns the value when the object cannot be coerced
@api public
# File lib/coercible/coercer/object.rb, line 121 def to_integer(value) coerce_with_method(value, :to_int, __method__) end
Create a String from the Object if possible
@example with a coercible object
coercer[Object].to_string("string") # => "string"
@example with an object that is not coercible
coercer[Object].to_string(value) # => value
@param [to_str, Object] value
@return [String]
returns a String when the object can be coerced
@return [Object]
returns the value when the object cannot be coerced
@api public
# File lib/coercible/coercer/object.rb, line 101 def to_string(value) coerce_with_method(value, :to_str, __method__) end
Generated with the Darkfish Rdoc Generator 2.