Class: Marvin::DSL::Proxy
- Inherits:
-
Perennial::Proxy
- Object
- Perennial::Proxy
- Marvin::DSL::Proxy
show all
- Defined in:
- lib/marvin/dsl.rb
Instance Method Summary
collapse
Constructor Details
#initialize(klass) ⇒ Proxy
Returns a new instance of Proxy.
7
8
9
10
|
# File 'lib/marvin/dsl.rb', line 7
def initialize(klass)
@prototype_klass = Class.new(klass)
@mapping = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &blk) ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/marvin/dsl.rb', line 34
def method_missing(name, *args, &blk)
name = name.to_sym
if @mapping.has_key?(name)
@klass.define_method(@mapping[name], &blk)
else
@klass.send(name, *args, &blk)
end
end
|
Instance Method Details
#define_shortcut(name, method_name) ⇒ Object
12
13
14
|
# File 'lib/marvin/dsl.rb', line 12
def define_shortcut(name, method_name)
@mapping[name] = method_name
end
|
#initialize_class! ⇒ Object
22
23
24
|
# File 'lib/marvin/dsl.rb', line 22
def initialize_class!
@klass = Class.new(@prototype_klass)
end
|
#shortdef(hash = {}) ⇒ Object
16
17
18
|
# File 'lib/marvin/dsl.rb', line 16
def shortdef(hash = {})
hash.each_pair { |k,v| define_shortcut(k, v) }
end
|
#to_class ⇒ Object
30
31
32
|
# File 'lib/marvin/dsl.rb', line 30
def to_class
@klass
end
|
#to_instance ⇒ Object
26
27
28
|
# File 'lib/marvin/dsl.rb', line 26
def to_instance
@klass.new
end
|