Module: Mozart
- Defined in:
- lib/mozart/value.rb,
lib/mozart/context.rb,
lib/mozart/version.rb,
lib/mozart/composite.rb,
lib/mozart/composable.rb,
lib/mozart/environment.rb,
lib/mozart/single_assignment.rb
Defined Under Namespace
Modules: Composable, Environment, SingleAssignment
Classes: Composite
Constant Summary
collapse
- VERSION =
"0.0.2"
- AmbiguousMessageError =
Class.new(StandardError)
Class Method Summary
collapse
Class Method Details
.context(*accepted_methods, &class_definition) ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/mozart/context.rb', line 2
def self.context(*accepted_methods, &class_definition)
Class.new do
def initialize(target)
self.target = target
end
define_method :respond_to_missing? do |m, *a|
accepted_methods.include?(m)
end
def method_missing(m, *a, &b)
raise NotImplementedError unless respond_to_missing?(m)
target.public_send(m, *a, &b)
end
private
attr_accessor :target
end
end
|
.value(*field_names, &block) ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/mozart/value.rb', line 2
def self.value(*field_names, &block)
Class.new do
define_method(:initialize) do |params={}|
raise ArgumentError unless params.keys == field_names
self.__data__ = {}
params.each { |k,v| __data__[k] = v }
__data__
end
def ==(other)
self.class == other.class && __data__ == other.__data__
end
alias_method :eql?, :==
def hash
__data__.hash
end
field_names.each do |name|
define_method(name) { __data__[name] }
end
protected
attr_accessor :__data__
end
end
|