solnic / coercible

Powerful, flexible and configurable coercion library. And nothing more.
MIT License
137 stars 16 forks source link

#coerced? backwards? #17

Open eval opened 10 years ago

eval commented 10 years ago

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.