class Class
-
The additions to the Ruby
Class
class required to support fOOrth.
-
library/introspection/class.rb -
Class
support for introspection.
Public Instance Methods
Create an instance of this fOOrth class.
Parameters:
-
vm - The current fOOrth virtual machine.
# File lib/fOOrth/core/class.rb, line 59 def create_foorth_instance(vm) (obj = self.new).foorth_init(vm) obj end
Add this class as a proxy class in the foorth class system.
Parameters:
-
proxy_name - the optional name of the proxy. Defaults to the Ruby name.
Returns:
-
The spec of the proxy class.
# File lib/fOOrth/core/class.rb, line 89 def create_foorth_proxy(proxy_name = nil) if proxy_name self.foorth_name = proxy_name end validate_class_name(foorth_name) error "F10: The class #{foorth_name} already exists." if $FOORTH_GLOBALS[foorth_name] install_foorth_class(foorth_name, self) end
Create a new fOOrth subclass of this class.
Parameters:
-
foorth_name
- Thefoorth_name
of the new sub-class.
Returns:
-
The spec of the subclass.
Note:
-
If a sub-class with the given name already exists, an exception is raised.
# File lib/fOOrth/core/class.rb, line 71 def create_foorth_subclass(foorth_name) if $FOORTH_GLOBALS[XfOOrth::SymbolMap.map(foorth_name)] error "F10: The class #{foorth_name} already exists." end validate_class_name(foorth_name) new_class = Class.new(self) {self.foorth_name = foorth_name} XfOOrth.const_set('XfOOrth_' + foorth_name, new_class) install_foorth_class(foorth_name, new_class) end
Get the name of the class or a safe default.
# File lib/fOOrth/core/class.rb, line 14 def foorth_class_name self.foorth_name || "AnonymousClass<#{self.object_id}>".freeze end
Investigate a method of this class.
# File lib/fOOrth/library/introspection/class.rb, line 28 def foorth_method_info(name) symbol, results = XfOOrth::SymbolMap.map_info(name) found = false if symbol if scrape_method_info(results, *map_foorth_shared_info(symbol)) found = true end if scrape_method_info(results, *map_foorth_exclusive_info(symbol, "Class")) found = true end results << ["Scope", "not found."] unless found end results end
Get the foorth name of this class.
Decree!
-
These are to be the only references to @_private_foorth_name!
# File lib/fOOrth/core/class.rb, line 9 def foorth_name @_private_foorth_name ||= name.gsub(/.*::/, '').freeze end
Set the foorth name of this class.
Decree!
-
These are to be the only references to @_private_foorth_name!
# File lib/fOOrth/core/class.rb, line 21 def foorth_name=(new_name) @_private_foorth_name = new_name.freeze end
Get introspection info.
# File lib/fOOrth/library/introspection/class.rb, line 48 def get_info results = [["Lineage", lineage]] get_exclusive_method_info(results, "Class") get_shared_method_info(results) results end
Get the lineage of this class.
# File lib/fOOrth/library/introspection/class.rb, line 18 def lineage #Ugly hack, sorry! if [Object, Module].include?(self) "Object" else foorth_class_name + " < " + superclass.lineage end end
Private Instance Methods
Connect the class named foorth_name
to the foorth system.
Returns:
-
The newly created spec object.
Endemic Code Smells
-
:reek:UtilityFunction
# File lib/fOOrth/core/class.rb, line 108 def install_foorth_class(new_name, new_class) fail "Bad name" unless new_name symbol = XfOOrth::SymbolMap.add_entry(new_name) $FOORTH_GLOBALS[symbol] = XfOOrth::ClassSpec.new(new_class, nil, [:class]) end
Get method information
Endemic Code Smells
-
:reek:UtilityFunction
# File lib/fOOrth/library/introspection/class.rb, line 62 def scrape_method_info(results, spec, info) if spec && !spec.has_tag?(:stub) (results << ["", ""]).concat(info).concat(spec.get_info) true else false end end
Is this a valid class name?
# File lib/fOOrth/core/class.rb, line 115 def validate_class_name(name) unless /^[A-Z][A-Za-z0-9]+$/ =~ name error "F10: Invalid class name #{name}" end end