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
Constant Summary
Constants inherited from Library
Instance Attribute Summary
Attributes inherited from Library
#class_commands, #lib_file, #namespace, #new_commands, #new_module, #no_alias_creation, #repo_dir
Instance Method Summary collapse
Methods inherited from Library
#clean_name, #command_object, #command_objects, handles, #initialize, #library_type, #local?, #marshal_dump, #marshal_load, #namespace_object, #set_attributes, #set_command_aliases, #set_config, #set_repo
Methods included from Loader
#check_for_method_conflicts, #detect_additions, #include_in_universe, #load, #load_module_commands, #load_source_and_set_module, #loaded_correctly?, #module_callbacks, #set_library_commands
Constructor Details
This class inherits a constructor from Boson::Library
Instance Method Details
#initialize_library_module ⇒ Object
30 31 32 33 34 |
# File 'lib/boson/libraries/module_library.rb', line 30 def initialize_library_module @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 |