Module: Origami::FieldAccessor
- Included in:
- Dictionary, Stream
- Defined in:
- lib/origami/object.rb
Overview
Provides an easier syntax for field access. The object must have the defined the methods #[] and #[]=.
Once included, object.Field will automatically resolve to object. References are automatically followed.
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(field, *args) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/origami/object.rb', line 97 def method_missing(field, *args) raise NoMethodError, "No method `#{field}' for #{self.class}" unless field =~ /^[[:upper:]]/ if field[-1] == '=' self[field[0..-2].to_sym] = args.first else object = self[field] object.is_a?(Reference) ? object.solve : object end end |
Instance Method Details
#respond_to_missing?(field) ⇒ Boolean
108 109 110 |
# File 'lib/origami/object.rb', line 108 def respond_to_missing?(field, *) not (field =~ /^[[:upper:]]/).nil? or super end |