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

Raises:

  • (NoMethodError)


143
144
145
146
147
148
149
150
151
152
# File 'lib/origami/object.rb', line 143

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

Returns:



154
155
156
# File 'lib/origami/object.rb', line 154

def respond_to_missing?(field, *)
    not (field =~ /^[[:upper:]]/).nil? or super
end