Class: String
Overview
Useful String methods for Jeweler: .true?, .to_b and .money
Instance Method Summary collapse
-
#money ⇒ Object
Parses a number by converting it to a Double, formatting it as money, and then converting it back to String Example: $32.50 (String).
-
#to_b ⇒ Object
Returns true if String is explicitly equal to ‘true’ Returns false if String is explicitly equal to ‘false’ raise ArgumentError if any other String is evaluated.
-
#true? ⇒ Boolean
Returns true if the string is equal to ‘true’.
-
#uglify ⇒ Object
Undoes a titleize by addinig underscores and making lowercase returns String.
Instance Method Details
#money ⇒ Object
Parses a number by converting it to a Double, formatting it as money, and then converting it back to String Example: $32.50 (String)
25 26 27 |
# File 'lib/bluehelmet/core_ext/String.rb', line 25 def money to_d.money.to_s end |
#to_b ⇒ Object
Returns true if String is explicitly equal to ‘true’ Returns false if String is explicitly equal to ‘false’ raise ArgumentError if any other String is evaluated
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bluehelmet/core_ext/String.rb', line 11 def to_b if to_s == 'true' true elsif to_s == 'false' false else # raise SyntaxError raise ArgumentError 'String being evaluated by to_b can only be equal to True or False' end end |
#true? ⇒ Boolean
Returns true if the string is equal to ‘true’
4 5 6 |
# File 'lib/bluehelmet/core_ext/String.rb', line 4 def true? to_s == 'true' end |
#uglify ⇒ Object
Undoes a titleize by addinig underscores and making lowercase returns String. ActionSupport alternative is ‘.parameterize` Example Nice Title -> nice_title (String)
32 33 34 |
# File 'lib/bluehelmet/core_ext/String.rb', line 32 def uglify self.gsub(' ', '_').downcase end |