Module: RubyEnum::InstanceMethods
- Defined in:
- lib/ruby_enum.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/ruby_enum.rb', line 14
def method_missing(method, *args, &block)
if method.to_s =~ /^(.*)\?/
enum_names = self.class.all.map(&:name)
expected_name = $1.to_sym
if enum_names.include?(expected_name)
return name == expected_name
end
end
super
end
|
Instance Method Details
#clone ⇒ Object
45
46
47
|
# File 'lib/ruby_enum.rb', line 45
def clone
raise TypeError, "can't clone instance of enum #{self.class}"
end
|
#dup ⇒ Object
49
50
51
|
# File 'lib/ruby_enum.rb', line 49
def dup
raise TypeError, "can't dupe instance of enum #{self.class}"
end
|
#name ⇒ Symbol
Returns the name of the enumeration instance.
41
42
43
|
# File 'lib/ruby_enum.rb', line 41
def name
@_name
end
|
#respond_to?(method) ⇒ Boolean
26
27
28
29
30
31
32
33
|
# File 'lib/ruby_enum.rb', line 26
def respond_to?(method)
if method.to_s =~ /^(.*)\?/
enum_names = self.class.all.map(&:name)
return enum_names.include? $1.to_sym
else
super
end
end
|
#value ⇒ String
Returns the associated value of the enumeration instance.
36
37
38
|
# File 'lib/ruby_enum.rb', line 36
def value
@_value
end
|