Class: RubyBreaker::Runtime::ObjectWrapper
- Inherits:
- BasicObject
- Defined in:
- lib/rubybreaker/runtime/object_wrapper.rb
Overview
This class represents the shell object that wraps around another object. Note that it is a subclass of BasicObject to keep it really concise. It also redirects the following methods (from BasicObject):
!, !=, ==, equal?, eql?, __id__, object_id, send, __send__, instance_eval, instance_exec
Instance Method Summary collapse
-
#__rubybreaker_obj ⇒ Object
This method returns the original object.
-
#__rubybreaker_type ⇒ Object
This method returns the type gathered so far for this object.
-
#initialize(obj) ⇒ ObjectWrapper
constructor
A new instance of ObjectWrapper.
-
#method_missing(mname, *args, &blk) ⇒ Object
This method missing method redirects all other method calls.
-
#respond_to?(mname) ⇒ Boolean
Only behave differently if it’s looking for
WRAPPED_INDICATORmethod.
Constructor Details
#initialize(obj) ⇒ ObjectWrapper
Returns a new instance of ObjectWrapper.
22 23 24 25 26 |
# File 'lib/rubybreaker/runtime/object_wrapper.rb', line 22 def initialize(obj) @__rubybreaker_obj = obj nom_type = TypeDefs::NominalType.new(obj.class) @__rubybreaker_type = TypeDefs::FusionType.new(nom_type,[]) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mname, *args, &blk) ⇒ Object
This method missing method redirects all other method calls.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rubybreaker/runtime/object_wrapper.rb', line 70 def method_missing(mname,*args,&blk) ::RubyBreaker.log("Method_missing for #{mname}") if GLOBAL_MONITOR_SWITCH.switch # Must handle send method specially (do not track them) if [:"__send__", :send].include?(mname) mname = args[0] args = args[1..-1] end @__rubybreaker_type.add_meth(mname) retval = @__rubybreaker_obj.send(mname, *args, &blk) retval = ObjectWrapper.new(retval) else retval = @__rubybreaker_obj.send(mname, *args, &blk) end return retval end |
Instance Method Details
#__rubybreaker_obj ⇒ Object
This method returns the original object.
29 30 31 |
# File 'lib/rubybreaker/runtime/object_wrapper.rb', line 29 def __rubybreaker_obj() return @__rubybreaker_obj end |
#__rubybreaker_type ⇒ Object
This method returns the type gathered so far for this object.
34 35 36 |
# File 'lib/rubybreaker/runtime/object_wrapper.rb', line 34 def __rubybreaker_type() return @__rubybreaker_type end |
#respond_to?(mname) ⇒ Boolean
Only behave differently if it’s looking for WRAPPED_INDICATOR method
64 65 66 67 |
# File 'lib/rubybreaker/runtime/object_wrapper.rb', line 64 def respond_to?(mname) return true if mname.to_sym == WRAPPED_INDICATOR return @__rubybreaker_obj.respond_to?(mname) end |