Class: Module
- Inherits:
-
Object
- Object
- Module
- Defined in:
- lib/tanuki/extensions/module.rb
Instance Method Summary collapse
-
#const_missing(sym) ⇒ Object
Runs Tanuki::Loader for every missing constant in any namespace.
-
#internal_attr_accessor(*syms) ⇒ Object
Creates a reader
symand a writersym=for the instance variable @_sym. -
#internal_attr_reader(*syms) ⇒ Object
Creates a reader
symfor the instance variable @_sym. -
#internal_attr_writer(*syms) ⇒ Object
Creates a writer
sym=for the instance variable @_sym.
Instance Method Details
#const_missing(sym) ⇒ Object
Runs Tanuki::Loader for every missing constant in any namespace.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/tanuki/extensions/module.rb', line 4 def const_missing(sym) klass = "#{name + '::' if name != 'Object'}#{sym}" paths = Dir.glob(Tanuki::Loader.combined_class_path(klass)) if paths.empty? unless Dir.glob(Tanuki::Loader.combined_class_dir(klass)).empty? return const_set(sym, Class.new) end else paths.reverse_each {|path| require path } return const_get(sym) if const_defined?(sym) end raise NameError, "uninitialized constant #{name}::#{sym}" end |
#internal_attr_accessor(*syms) ⇒ Object
Creates a reader sym and a writer sym= for the instance variable @_sym.
19 20 21 22 |
# File 'lib/tanuki/extensions/module.rb', line 19 def internal_attr_accessor(*syms) internal_attr_reader(*syms) internal_attr_writer(*syms) end |
#internal_attr_reader(*syms) ⇒ Object
Creates a reader sym for the instance variable @_sym.
25 26 27 28 29 30 31 |
# File 'lib/tanuki/extensions/module.rb', line 25 def internal_attr_reader(*syms) syms.each do |sym| ivar = "@_#{sym}".to_sym instance_variable_set(ivar, nil) unless instance_variable_defined? ivar class_eval "def #{sym};#{ivar};end" end end |
#internal_attr_writer(*syms) ⇒ Object
Creates a writer sym= for the instance variable @_sym.
34 35 36 37 38 39 40 |
# File 'lib/tanuki/extensions/module.rb', line 34 def internal_attr_writer(*syms) syms.each do |sym| ivar = "@_#{sym}".to_sym instance_variable_set(ivar, nil) unless instance_variable_defined? ivar class_eval "def #{sym}=(obj);#{ivar}=obj;end" end end |