Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/fOOrth/core/object.rb,
lib/fOOrth/monkey_patch/object.rb,
lib/fOOrth/library/clone_library.rb
Overview
-
Runtime clone library support in Object.
Instance Method Summary collapse
-
#cache_exclusive_method(symbol, &block) ⇒ Object
Load the new exclusive method into the object.
-
#create_exclusive_method(name, spec_class, options, &block) ⇒ Object
Create an exclusive method on this fOOrth object.
-
#error(msg) ⇒ Object
Fail with XfOOrthError argument error.
-
#foorth_coerce(_arg) ⇒ Object
Coerce the argument to match my type.
-
#foorth_embed ⇒ Object
Raise a fOOrth language internal exception as this operation is not allowed.
-
#foorth_exclusive ⇒ Object
Access/create the object’s exclusive fOOrth dictionary.
-
#foorth_has_exclusive? ⇒ Boolean
Does this object have exclusive methods defined on it?
Decree! * These are to be the only reference to @_private_foorth_exclusive!. -
#foorth_init(_vm) ⇒ Object
The default foorth_init method does nothing.
-
#foorth_name ⇒ Object
Get the foorth name of this object.
-
#full_clone_exclude ⇒ Object
The full clone data member clone exclusion control.
-
#map_foorth_exclusive(symbol) ⇒ Object
Map the symbol to a specification or nil if there is no mapping.
-
#method_missing(symbol, *args, &block) ⇒ Object
The method_missing hook is used to provide meaningful error messages when problems are encountered.
-
#to_foorth_b ⇒ Object
Convert this object to a fOOrth boolean.
-
#to_foorth_c ⇒ Object
Convert this object to a single character string.
-
#to_foorth_n ⇒ Object
Convert this object to a numeric.
-
#to_foorth_r ⇒ Object
Convert this object to a rational.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
The method_missing hook is used to provide meaningful error messages when problems are encountered.
Parameters:
-
symbol - The symbol of the missing method.
-
args - Any arguments that were passed to that method.
-
block - Any block that might have passed to the method.
Note:
-
Since stubs for Object class do not create methods, an attempt is made
to execute the stub if the symbol maps and is in the Object class.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fOOrth/core/object.rb', line 66 def method_missing(symbol, *args, &block) if (name = XfOOrth::SymbolMap.unmap(symbol)) if (stub_spec = Object.foorth_shared[symbol]) self.instance_exec(*args, &stub_spec.does) else error "F20: A #{self.foorth_name} does not understand #{name} (#{symbol})." end else super end end |
Instance Method Details
#cache_exclusive_method(symbol, &block) ⇒ Object
Load the new exclusive method into the object.
41 42 43 44 45 |
# File 'lib/fOOrth/core/object.rb', line 41 def cache_exclusive_method(symbol, &block) define_singleton_method(symbol, &block) rescue TypeError error "F13: Exclusive methods not allowed for type: #{self.class.foorth_name}" end |
#create_exclusive_method(name, spec_class, options, &block) ⇒ Object
Create an exclusive method on this fOOrth object.
Parameters:
-
name - The name of the method to create.
-
spec_class - The specification class to use.
-
options - An array of options.
-
block - A block to associate with the name.
Returns
-
The spec created for the shared method.
33 34 35 36 37 38 |
# File 'lib/fOOrth/core/object.rb', line 33 def create_exclusive_method(name, spec_class, , &block) sym = XfOOrth::SymbolMap.add_entry(name) spec = spec_class.new(name, sym, , &block) cache_exclusive_method(sym, &spec.does) foorth_exclusive[sym] = spec end |
#error(msg) ⇒ Object
Fail with XfOOrthError argument error.
32 33 34 |
# File 'lib/fOOrth/monkey_patch/object.rb', line 32 def error(msg) fail XfOOrth::XfOOrthError, msg, caller end |
#foorth_coerce(_arg) ⇒ Object
Coerce the argument to match my type. Stub
39 40 41 |
# File 'lib/fOOrth/monkey_patch/object.rb', line 39 def foorth_coerce(_arg) error "F40: Cannot coerce to a #{self.foorth_name}" end |
#foorth_embed ⇒ Object
Raise a fOOrth language internal exception as this operation is not allowed.
7 8 9 |
# File 'lib/fOOrth/monkey_patch/object.rb', line 7 def error "F40: Can't embed class #{self.class.to_s}" end |
#foorth_exclusive ⇒ Object
Access/create the object’s exclusive fOOrth dictionary.
Decree!
-
These are to be the only reference to @_private_foorth_exclusive!
14 15 16 |
# File 'lib/fOOrth/core/object.rb', line 14 def foorth_exclusive @_private_foorth_exclusive ||= Hash.new end |
#foorth_has_exclusive? ⇒ Boolean
Does this object have exclusive methods defined on it?
Decree!
-
These are to be the only reference to @_private_foorth_exclusive!
21 22 23 |
# File 'lib/fOOrth/core/object.rb', line 21 def foorth_has_exclusive? instance_variable_defined?(:@_private_foorth_exclusive) end |
#foorth_init(_vm) ⇒ Object
The default foorth_init method does nothing.
54 55 |
# File 'lib/fOOrth/core/object.rb', line 54 def foorth_init(_vm) end |
#foorth_name ⇒ Object
Get the foorth name of this object.
7 8 9 |
# File 'lib/fOOrth/core/object.rb', line 7 def foorth_name "#{self.class.foorth_name} instance" end |
#full_clone_exclude ⇒ Object
The full clone data member clone exclusion control
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fOOrth/library/clone_library.rb', line 35 def full_clone_exclude vm = Thread.current[:vm] self.foorth_exclude(vm) vm.pop.map do |entry| if (sym = XfOOrth::SymbolMap.map(entry)) ("@" + sym.to_s).to_sym else entry end end end |
#map_foorth_exclusive(symbol) ⇒ Object
Map the symbol to a specification or nil if there is no mapping.
48 49 50 51 |
# File 'lib/fOOrth/core/object.rb', line 48 def map_foorth_exclusive(symbol) (foorth_has_exclusive? && foorth_exclusive[symbol]) || self.class.map_foorth_shared(symbol) end |
#to_foorth_b ⇒ Object
Convert this object to a fOOrth boolean.
12 13 14 |
# File 'lib/fOOrth/monkey_patch/object.rb', line 12 def to_foorth_b true end |
#to_foorth_c ⇒ Object
Convert this object to a single character string.
17 18 19 |
# File 'lib/fOOrth/monkey_patch/object.rb', line 17 def to_foorth_c "\x00" end |
#to_foorth_n ⇒ Object
Convert this object to a numeric. Returns nil for fail.
22 23 24 |
# File 'lib/fOOrth/monkey_patch/object.rb', line 22 def to_foorth_n nil end |
#to_foorth_r ⇒ Object
Convert this object to a rational. Returns nil for fail.
27 28 29 |
# File 'lib/fOOrth/monkey_patch/object.rb', line 27 def to_foorth_r nil end |