Class: EacRubyUtils::Enum::Value

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/eac_ruby_utils/enum.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, key, args, &block) ⇒ Value

Returns a new instance of Value.



43
44
45
46
47
48
# File 'lib/eac_ruby_utils/enum.rb', line 43

def initialize(klass, key, args, &block)
  @klass = klass
  @key = ::EacRubyUtils::Inflector.variableize(key.to_s).to_sym
  @args = args
  @block = block
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



41
42
43
# File 'lib/eac_ruby_utils/enum.rb', line 41

def args
  @args
end

#blockObject (readonly)

Returns the value of attribute block.



41
42
43
# File 'lib/eac_ruby_utils/enum.rb', line 41

def block
  @block
end

#keyObject (readonly)

Returns the value of attribute key.



41
42
43
# File 'lib/eac_ruby_utils/enum.rb', line 41

def key
  @key
end

#klassObject (readonly)

Returns the value of attribute klass.



41
42
43
# File 'lib/eac_ruby_utils/enum.rb', line 41

def klass
  @klass
end

Instance Method Details

#<=>(other) ⇒ Object



50
51
52
# File 'lib/eac_ruby_utils/enum.rb', line 50

def <=>(other)
  key <=> other.key
end

#applyObject



54
55
56
57
58
59
# File 'lib/eac_ruby_utils/enum.rb', line 54

def apply
  define_constant
  define_class_method

  self
end

#class_method_nameString

Returns:



62
63
64
# File 'lib/eac_ruby_utils/enum.rb', line 62

def class_method_name
  key.to_s
end

#constant_nameString

Returns:



67
68
69
# File 'lib/eac_ruby_utils/enum.rb', line 67

def constant_name
  class_method_name.upcase
end

#valueObject



71
72
73
# File 'lib/eac_ruby_utils/enum.rb', line 71

def value
  @value ||= uncached_value
end