Module: ScopedStruct::MethodCarrier
- Defined in:
- lib/scoped_struct.rb
Defined Under Namespace
Classes: BlankSlate
Class Method Summary collapse
- .extend_object(base) ⇒ Object
- .extract_method_names(method_declarations) ⇒ Object
- .set_scoped_methods(scope_name, method_declarations) ⇒ Object
Class Method Details
.extend_object(base) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/scoped_struct.rb', line 24 def self.extend_object(base) @@method_names.each do |method_name| base.class_eval %Q( alias #{@@scope_name + '_' + method_name} #{method_name} undef #{method_name} ) end end |
.extract_method_names(method_declarations) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/scoped_struct.rb', line 41 def self.extract_method_names(method_declarations) cls = BlankSlate.new original_methods = cls.methods cls.extend(Module.new(&method_declarations)) cls.methods - original_methods end |
.set_scoped_methods(scope_name, method_declarations) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/scoped_struct.rb', line 33 def self.set_scoped_methods(scope_name, method_declarations) raise SyntaxError.new("No block passed to scope command.") if method_declarations.nil? @@scope_name = scope_name.to_s @@method_names = extract_method_names(method_declarations).collect{|m| m.to_s} raise SyntaxError.new("No methods defined in scope block.") unless @@method_names.any? method_declarations.call end |