Module: Frenchy::Enum
- Defined in:
- lib/frenchy/enum.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#tag ⇒ Object
Returns the value of attribute tag.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #initialize(attrs = {}) ⇒ Object
- #inspect ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
- #to_sym ⇒ Object
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/frenchy/enum.rb', line 12 def name @name end |
#tag ⇒ Object
Returns the value of attribute tag.
12 13 14 |
# File 'lib/frenchy/enum.rb', line 12 def tag @tag end |
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/frenchy/enum.rb', line 3 def self.included(base) base.extend(ClassMethods) base.class_eval do @enums = {} @default = nil end end |
Instance Method Details
#==(other) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/frenchy/enum.rb', line 40 def ==(other) (other.is_a?(Symbol) && (name == other)) || (other.respond_to?(:to_i) && (other.to_i == tag)) || (other.respond_to?(:to_s) && (other.to_s == to_s || other.to_s == name.to_s)) || super end |
#initialize(attrs = {}) ⇒ Object
14 15 16 17 18 |
# File 'lib/frenchy/enum.rb', line 14 def initialize(attrs={}) attrs.each do |k, v| send("#{k}=", v) if respond_to?("#{k}=") end end |
#inspect ⇒ Object
20 21 22 |
# File 'lib/frenchy/enum.rb', line 20 def inspect "\#<#{self.class.name}::#{name}=#{tag}>" end |
#to_i ⇒ Object
24 25 26 |
# File 'lib/frenchy/enum.rb', line 24 def to_i tag end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/frenchy/enum.rb', line 36 def to_s name.to_s.underscore end |
#to_str ⇒ Object
28 29 30 |
# File 'lib/frenchy/enum.rb', line 28 def to_str to_s end |
#to_sym ⇒ Object
32 33 34 |
# File 'lib/frenchy/enum.rb', line 32 def to_sym name end |