Class: Dux::IndifferentString
- Inherits:
-
String
- Object
- String
- Dux::IndifferentString
- Defined in:
- lib/dux/indifferent_string.rb
Overview
A string value that is programmatically equivalent to its symbol representation.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Test basic equality.
-
#===(other) ⇒ Object
Test case equality.
-
#initialize(stringish) ⇒ IndifferentString
constructor
A new instance of IndifferentString.
Constructor Details
#initialize(stringish) ⇒ IndifferentString
Returns a new instance of IndifferentString.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dux/indifferent_string.rb', line 5 def initialize(stringish) stringified = case stringish when String, Dux::IndifferentString then stringish when Symbol then stringish.to_s when Dux[:to_str] then stringish.to_str else if Dux.attempt(stringish, :acts_like?, :string) stringish.to_s else raise TypeError, "Not a string or symbol: #{stringish}" end end super(stringified) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Test basic equality.
25 26 27 28 29 30 31 |
# File 'lib/dux/indifferent_string.rb', line 25 def ==(other) if other.kind_of?(Symbol) self == other.to_s else super end end |
#===(other) ⇒ Object
Test case equality
38 39 40 41 42 43 44 |
# File 'lib/dux/indifferent_string.rb', line 38 def ===(other) if other.kind_of?(Symbol) self == other.to_s else super end end |