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
47
48
49
|
# File 'lib/ruby_enum.rb', line 47
def clone
raise TypeError, "can't clone instance of enum #{self.class}"
end
|
#dup ⇒ Object
51
52
53
|
# File 'lib/ruby_enum.rb', line 51
def dup
raise TypeError, "can't dupe instance of enum #{self.class}"
end
|
#name ⇒ Symbol
Returns the name of the enumeration instance.
43
44
45
|
# File 'lib/ruby_enum.rb', line 43
def name
@_name
end
|
#respond_to?(method) ⇒ Boolean
26
27
28
29
30
31
32
33
34
|
# 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
super
end
|
#value ⇒ String
Returns the associated value of the enumeration instance.
38
39
40
|
# File 'lib/ruby_enum.rb', line 38
def value
@_value
end
|