Class: Jtor::StdLib::SuperObject

Inherits:
Object
  • Object
show all
Defined in:
lib/jtor-stdlib/superobject.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ SuperObject

Returns a new instance of SuperObject.



4
5
6
# File 'lib/jtor-stdlib/superobject.rb', line 4

def initialize(obj)
  @obj = obj
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &block) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/jtor-stdlib/superobject.rb', line 8

def method_missing(symbol, *args, &block)
  superclass = @obj.class.superclass
  if superclass < Base # If it's a Jtor class
    superclass.lookup(@obj, symbol, *args)
  else # All other classes (from http://stackoverflow.com/a/1251199)
    superclass.instance_method(symbol).bind(@obj).call(*args, &block)
  end
end