Module: SymbolRespondTo
- Defined in:
- lib/json2/symbol_respond_to.rb
Overview
Simplify the use of duck typing in case/when structure.
Examples
a = []
b = ~:each
b.call(a) #=> true
# How is this simplification!? Are you kiding me?
# We can use it like this:
case object
when ~:each then
Instance Method Summary collapse
-
#~@ ⇒ Object
Returns Boolean.
Instance Method Details
#~@ ⇒ Object
Returns Boolean.
20 21 22 |
# File 'lib/json2/symbol_respond_to.rb', line 20 def ~@ ->(object) { object.respond_to?(self) } end |