Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/formatted_string.rb
Instance Method Summary collapse
-
#format ⇒ Object
Use this to see what format you’ve set to the string.
-
#format=(fmat) ⇒ Object
Use this to specify that this string is a certain format.
-
#formatted(fmat) ⇒ Object
Simply sets format=, but returns the string object.
Instance Method Details
#format ⇒ Object
Use this to see what format you’ve set to the string.
s = '<some><xml>text</xml></some>'
s.format = :xml
s.format
=> :xml
10 11 12 |
# File 'lib/formatted_string.rb', line 10 def format @format end |
#format=(fmat) ⇒ Object
Use this to specify that this string is a certain format.
s = '<some><xml>text</xml></some>'
s.format = :xml
s.to_hash # a method extended onto the `s' object from the xml format module.
=> {'some' => {'xml' => 'text'}}
19 20 21 22 23 |
# File 'lib/formatted_string.rb', line 19 def format=(fmat) require "formatted_string/formats/#{fmat.to_s}" rescue nil extend Object.module_eval("::FormattedString::Formats::#{Inflector.camelize(fmat.to_s)}", __FILE__, __LINE__) @format = [@format, fmat].flatten.compact end |
#formatted(fmat) ⇒ Object
Simply sets format=, but returns the string object.
26 27 28 29 |
# File 'lib/formatted_string.rb', line 26 def formatted(fmat) self.format = fmat self end |