Class: Reference
Overview
Reference
Reference provides a way to access object indirectly. This allows for the object itself to be changed on the fly.
Synopsis
a = "HELLO"
b = ref(a)
puts b #=> "HELLO"
c = 10
b.become(c)
puts b #=> "10"
Class Method Summary collapse
Instance Method Summary collapse
- #__value__ ⇒ Object (also: #instance_delegate)
- #become(obj) ⇒ Object
- #method_missing(*args, &block) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
57 58 59 |
# File 'lib/more/facets/reference.rb', line 57 def method_missing(*args, &block) @ref.__send__(*args, &block) end |
Class Method Details
.new(obj) ⇒ Object
51 52 53 54 55 |
# File 'lib/more/facets/reference.rb', line 51 def self.new(obj) ref = allocate ref.become obj ref end |