Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/fOOrth/core/object.rb,
lib/fOOrth/monkey_patch/object.rb,
lib/fOOrth/library/clone_library.rb,
lib/fOOrth/library/formatting/object.rb,
lib/fOOrth/library/introspection/object.rb
Overview
-
library/introspection/object.rb - Object support for introspection.
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.
-
#f20_error(recvr, name, symbol) ⇒ Object
A helper macro for method not understood errors.
-
#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! * This method and the previous are to be the only references to the @_private_foorth_exclusive variable. -
#foorth_method_info(name) ⇒ Object
Investigate a method of this object.
-
#foorth_name ⇒ Object
Get the foorth name of this object.
-
#foorth_string_freeze ⇒ Object
Freeze only pure strings.
-
#format_description(max_width) ⇒ Object
Create a bullet point description from this object.
-
#full_clone_exclude ⇒ Object
The full clone data member clone exclusion control.
-
#get_info ⇒ Object
Get introspection info.
-
#lineage ⇒ Object
Get the lineage of this object.
-
#map_foorth_exclusive(symbol) ⇒ Object
Map the symbol to a specification or nil if there is no mapping.
-
#map_foorth_exclusive_info(symbol, shallow = nil) ⇒ 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.
-
#prepare_bullet_data ⇒ Object
Get data ready for being in a bullet point.
-
#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. This
ensures that the case specific stub code is used rather than the generic
code in this method.
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 f20_error(self, name, symbol) end else super end end |
Instance Method Details
#cache_exclusive_method(symbol, &block) ⇒ Object
Load the new exclusive method into the object.
43 44 45 46 47 |
# File 'lib/fOOrth/core/object.rb', line 43 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.
35 36 37 38 39 40 |
# File 'lib/fOOrth/core/object.rb', line 35 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.
37 38 39 |
# File 'lib/fOOrth/monkey_patch/object.rb', line 37 def error(msg) fail XfOOrth::XfOOrthError, msg, caller end |
#f20_error(recvr, name, symbol) ⇒ Object
A helper macro for method not understood errors.
42 43 44 45 46 |
# File 'lib/fOOrth/monkey_patch/object.rb', line 42 def f20_error(recvr, name, symbol) fail XfOOrth::XfOOrthError, "F20: A #{recvr.foorth_name} does not understand #{name} (#{symbol.inspect}).", caller end |
#foorth_coerce(_arg) ⇒ Object
Coerce the argument to match my type. Stub
51 52 53 |
# File 'lib/fOOrth/monkey_patch/object.rb', line 51 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.foorth_class_name}" end |
#foorth_exclusive ⇒ Object
Access/create the object’s exclusive fOOrth dictionary.
Decree!
-
This method and the next are to be the only references
to the @_private_foorth_exclusive variable.
15 16 17 |
# File 'lib/fOOrth/core/object.rb', line 15 def foorth_exclusive @_private_foorth_exclusive ||= Hash.new end |
#foorth_has_exclusive? ⇒ Boolean
Does this object have exclusive methods defined on it?
Decree!
-
This method and the previous are to be the only references
to the @_private_foorth_exclusive variable.
23 24 25 |
# File 'lib/fOOrth/core/object.rb', line 23 def foorth_has_exclusive? instance_variable_defined?(:@_private_foorth_exclusive) end |
#foorth_method_info(name) ⇒ Object
Investigate a method of this object.
Endemic Code Smells
-
:reek:FeatureEnvy
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fOOrth/library/introspection/object.rb', line 29 def foorth_method_info(name) symbol, results = XfOOrth::SymbolMap.map_info(name) found = false if symbol spec, info = map_foorth_exclusive_info(symbol) if spec && !spec.has_tag?(:stub) (results << ["", ""]).concat(info).concat(spec.get_info) found = true end results << ["Scope", "not found."] unless found end results 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".freeze end |
#foorth_string_freeze ⇒ Object
Freeze only pure strings
32 33 34 |
# File 'lib/fOOrth/monkey_patch/object.rb', line 32 def foorth_string_freeze self end |
#format_description(max_width) ⇒ Object
Create a bullet point description from this object.
7 8 9 |
# File 'lib/fOOrth/library/formatting/object.rb', line 7 def format_description(max_width) self.to_s.format_description(max_width) 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 |
#get_info ⇒ Object
Get introspection info.
18 19 20 21 22 23 24 |
# File 'lib/fOOrth/library/introspection/object.rb', line 18 def get_info results = [["Type", foorth_name]] get_instance_variable_info(results) get_exclusive_method_info(results, "Exclusive") results end |
#lineage ⇒ Object
Get the lineage of this object.
48 49 50 |
# File 'lib/fOOrth/library/introspection/object.rb', line 48 def lineage foorth_name + " < " + self.class.lineage end |
#map_foorth_exclusive(symbol) ⇒ Object
Map the symbol to a specification or nil if there is no mapping.
50 51 52 53 |
# File 'lib/fOOrth/core/object.rb', line 50 def map_foorth_exclusive(symbol) (foorth_has_exclusive? && foorth_exclusive[symbol]) || self.class.map_foorth_shared(symbol) end |
#map_foorth_exclusive_info(symbol, shallow = nil) ⇒ Object
Map the symbol to a specification or nil if there is no mapping.
7 8 9 10 11 12 13 14 15 |
# File 'lib/fOOrth/library/introspection/object.rb', line 7 def map_foorth_exclusive_info(symbol, shallow=nil) if (foorth_has_exclusive? && (spec = foorth_exclusive[symbol])) [spec, [["Object", foorth_name], ["Scope", "Exclusive"]]] elsif !shallow self.class.map_foorth_shared_info(symbol) else [nil, nil] end end |
#prepare_bullet_data ⇒ Object
Get data ready for being in a bullet point.
12 13 14 |
# File 'lib/fOOrth/library/formatting/object.rb', line 12 def prepare_bullet_data ["*", self] 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 |