Class: Boson::ModuleLibrary
- Defined in:
- lib/boson/libraries/module_library.rb
Overview
This library takes a module or class as a library’s name and loads its class methods as commands. If no commands are given it defaults to loading all of its class methods as commands. The only method callback (see Loader) this library calls on the original module/class is config().
Example:
>> load_library Math, :commands=>%w{sin cos tan}
=> true
# Let's brush up on ol trig
>> sin (Math::PI/2)
=> 1.0
>> tan (Math::PI/4)
=> 1.0
# Close enough :)
>> cos (Math::PI/2)
=> 6.12323399573677e-17
Instance Attribute Summary
Attributes inherited from Library
Attributes included from Library::NamespaceLoader
#indexed_namespace, #object_namespace
Attributes included from Library::Namespacer
Attributes included from Library::Libraries
Attributes included from Library::Alias
#class_commands, #no_alias_creation
Attributes included from Library::Save
Instance Method Summary collapse
Methods included from Library::NamespaceLoader
#actual_load_commands, #clean_library_commands, #handle_method_conflict_error, #method_conflicts, #set_library_commands
Methods included from Library::Namespacer
Methods included from Library::LibrariesLoader
#after_include, #before_load_commands, #detect_additions, #module_callbacks
Methods included from Library::Libraries
Methods included from Library::AliasLoader
#before_load_commands, #load_commands?
Methods included from Library::Save
#before_initialize, #config, #marshal_dump, #marshal_load, #set_repo
Instance Method Details
#load_commands ⇒ Object
30 31 32 33 34 |
# File 'lib/boson/libraries/module_library.rb', line 30 def load_commands @class_commands = {@module.to_s=>Array(@commands).empty? ? @module.methods(false) : @commands } @module = nil super end |
#set_name(name) ⇒ Object
24 25 26 27 28 |
# File 'lib/boson/libraries/module_library.rb', line 24 def set_name(name) @module = name underscore_lib = name.to_s[/^Boson::Commands/] ? name.to_s.split('::')[-1] : name.to_s Util.underscore(underscore_lib) end |