Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/tidbits.rb
Instance Method Summary collapse
-
#method_missing(method_name, *arguments) ⇒ Object
this lets you do things like f = ‘foo’ f.foo? #=> true f.woo? #=> false.
-
#sluggify(length = 40) ⇒ Object
squeezes non-alphanumeric character sequences down to one underscore also makes sure it doesn’t start or end with an underscore: W neither letter or digit W Any non-word character [^a-zA-Z0-9_] more at www.roblocher.com/technotes/regexp.aspx.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments) ⇒ Object
this lets you do things like f = ‘foo’ f.foo? #=> true f.woo? #=> false
inspired by StringInquirer in ActiveSupport
19 20 21 22 23 24 25 |
# File 'lib/tidbits.rb', line 19 def method_missing(method_name, *arguments) if method_name.to_s[-1,1] == "?" self == method_name.to_s[0..-2] else super end end |
Instance Method Details
#sluggify(length = 40) ⇒ Object
squeezes non-alphanumeric character sequences down to one underscore also makes sure it doesn’t start or end with an underscore: W neither letter or digit W Any non-word character [^a-zA-Z0-9_]
more at http://www.roblocher.com/technotes/regexp.aspx
9 10 11 |
# File 'lib/tidbits.rb', line 9 def sluggify(length = 40) downcase.gsub(/\W/, ' ').strip.gsub(' ', '-').squeeze('-') end |