Class | Coercible::Coercer::Object |
In: |
lib/coercible/coercer/object.rb
|
Parent: | Object |
COERCION_METHOD_REGEXP | = | /\Ato_/.freeze |
coercers | [R] |
Return coercers object
@return [Coercer] @api private |
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
Inspect the coercer object
@example
coercer[Object].inspect # => "<Coercer::Object primitive=Object>"
@return [String]
@api public
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
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
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
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