Class: E9Crm::LabeledString
- Inherits:
-
String
- Object
- String
- E9Crm::LabeledString
- Defined in:
- lib/e9_crm/rails_extensions.rb
Overview
Simple string subclass that lets you query the string against a “label” it was initialized with. e.g.
LabeledString.new(:omfg, 'whatever').omfg? #=> true
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Instance Method Summary collapse
-
#initialize(label, *args) ⇒ LabeledString
constructor
A new instance of LabeledString.
- #method_missing(method_name, *args) ⇒ Object
Constructor Details
#initialize(label, *args) ⇒ LabeledString
Returns a new instance of LabeledString.
30 31 32 33 |
# File 'lib/e9_crm/rails_extensions.rb', line 30 def initialize(label, *args) @label = label if label.is_a?(Symbol) super(*args) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/e9_crm/rails_extensions.rb', line 35 def method_missing(method_name, *args) if @label && method_name.to_s[-1,1] == '?' method_name.to_s[0..-2] == @label.to_s else super end end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
28 29 30 |
# File 'lib/e9_crm/rails_extensions.rb', line 28 def label @label end |