coercible icon indicating copy to clipboard operation
coercible copied to clipboard

#coerced? backwards?

Open eval opened this issue 10 years ago • 0 comments

The implementation of #coerced? is not in line with the documentation (and seems counterintuitive).

The docs state:

# @example when coercion was successful
#     coercer[String].coerced?(1) # => true

The actual behavior is:

coercer = Coercible::Coercer.new
coercer[String].coerced?(1) # => false
coercer[String].coerced?("1") # => true

Maybe I get the idea of a coercer backwards, but the docs seem to describe what I would expect:

string_coercer = Coercible::Coercer.new[String]
string_coercer.coerced?(string_coercer.to_boolean('1')) # => true
# in general:
# x_coercer.coerced?(<value not of type X>) # => true
# x_coercer.coerced?(<value of type X>) # => false

Let me know - I can submit a PR either way.

eval avatar Aug 29 '14 12:08 eval