Module: Alf::Support::TupleScope::OwnMethods
- Defined in:
- lib/alf-support/alf/support/tuple_scope.rb
Instance Method Summary collapse
- #[](what) ⇒ Object
-
#__build(tuple) ⇒ Object
Builds this scope with a tuple.
-
#__set_tuple(tuple) ⇒ TupleScope
Sets the next tuple to use.
- #inspect ⇒ Object
-
#respond_to?(name) ⇒ Boolean
Returns true if the decorated tuple has ‘name` as key.
- #to_s ⇒ Object
Instance Method Details
#[](what) ⇒ Object
54 55 56 |
# File 'lib/alf-support/alf/support/tuple_scope.rb', line 54 def [](what) @tuple[what] end |
#__build(tuple) ⇒ Object
Builds this scope with a tuple.
This method should be called only once and installs instance methods on the scope with keys of tuple.
45 46 47 48 49 50 51 52 |
# File 'lib/alf-support/alf/support/tuple_scope.rb', line 45 def __build(tuple) tuple.keys.each do |k| (class << self; self; end).send(:define_method, k) do @tuple[k] end end self end |
#__set_tuple(tuple) ⇒ TupleScope
Sets the next tuple to use.
On first call, this method installs the scope as a side effect unless a tuple has already been provided at construction.
35 36 37 38 39 |
# File 'lib/alf-support/alf/support/tuple_scope.rb', line 35 def __set_tuple(tuple) __build(tuple) if @tuple.nil? @tuple = tuple self end |
#inspect ⇒ Object
62 63 64 |
# File 'lib/alf-support/alf/support/tuple_scope.rb', line 62 def inspect @tuple.inspect end |
#respond_to?(name) ⇒ Boolean
Returns true if the decorated tuple has ‘name` as key.
23 24 25 26 |
# File 'lib/alf-support/alf/support/tuple_scope.rb', line 23 def respond_to?(name) return true if @tuple && @tuple.has_key?(name) super end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/alf-support/alf/support/tuple_scope.rb', line 58 def to_s @tuple.to_s end |