Last active
August 29, 2015 14:06
-
-
Save Igosuki/152e2aec3d37c73156bc to your computer and use it in GitHub Desktop.
Pass-through struct to deserialize an API into YAML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Duration < Struct.new(:value, :quantity) | |
def method_missing id, *args | |
raise "Illegal Duration" if !value.is_a?(Numeric) || ![:years, :days, :weeks, :months, :hours, :minutes, :seconds].include?(quantity.to_sym) | |
value.send(quantity.to_sym).send(id.id2name.to_sym) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I do not get the use for it
... so what.
(Also
args
are ignored ? And I do not getid.id2name.to_sym
since if we call id2name on id it means it is already a symbol so we do not callto_sym
on it)