Class Index [+]

Quicksearch

Ramaze::CoreExtensions::String

Extensions for String


Extensions for String


Extensions for String


Extensions for String


Extensions for String


Extensions for String


Extensions for String


Extensions for String

Public Instance Methods

camel_case() click to toggle source

Simple transformation to CamelCase from snake_case

@example

 'foo_bar'.camel_case # => 'FooBar'
    # File lib/ramaze/snippets/string/camel_case.rb, line 14
14:       def camel_case
15:         split('_').map{|e| e.capitalize}.join
16:       end
end_with?(other) click to toggle source

Compatibility with 1.9

    # File lib/ramaze/snippets/string/end_with.rb, line 10
10:         def end_with?(other)
11:           other = other.to_s
12:           self[-other.size, other.size] == other
13:         end
escape(which = :html) click to toggle source

String#escape is an extensible escaping mechanism for string. currently it suports

  '<div>foo bar</div>'.esc(:html)
  'foo bar'.esc(:uri)
  'foo bar'.esc(:cgi)
    # File lib/ramaze/snippets/string/esc.rb, line 13
13:       def escape which = :html
14:         case which
15:         when :html
16:           Rack::Utils.escape_html(self)
17:         when :cgi
18:           Rack::Utils.escape(self)
19:         when :uri
20:           ::URI.escape(self)
21:         else
22:           raise ArgumentError, "do not know how to escape '#{ which }'"
23:         end
24:       end
ord() click to toggle source

compatibility with Ruby 1.9

    # File lib/ramaze/snippets/string/ord.rb, line 10
10:         def ord
11:           self[0]
12:         end
snake_case() click to toggle source

convert to snake_case from CamelCase

@example

 'FooBar'.snake_case # => 'foo_bar'
    # File lib/ramaze/snippets/string/snake_case.rb, line 13
13:       def snake_case
14:         gsub(/\B[A-Z][^A-Z]/, '_\&').downcase.gsub(' ', '_')
15:       end
start_with?(other) click to toggle source

Compatibility with 1.9

    # File lib/ramaze/snippets/string/start_with.rb, line 7
 7:         def start_with?(other)
 8:           other = other.to_s
 9:           self[0, other.size] == other
10:         end
ui() click to toggle source
Alias for: unindent
ui!() click to toggle source
Alias for: unindent!
unindent() click to toggle source

Useful for writing indented String and unindent on demand, based on the first line with indentation.

    # File lib/ramaze/snippets/string/unindent.rb, line 7
 7:       def unindent
 8:         find_indent = proc{ |l| l.find{|l| !l.strip.empty?}.to_s[/^(\s+)/, 1] }
 9: 
10:         lines = self.split("\n")
11:         space = find_indent[lines]
12:         space = find_indent[lines.reverse] unless space
13: 
14:         strip.gsub(/^#{space}/, '')
15:       end
Also aliased as: ui
unindent!() click to toggle source

Destructive variant of undindent, replacing the String

    # File lib/ramaze/snippets/string/unindent.rb, line 19
19:       def unindent!
20:         self.replace unindent
21:       end
Also aliased as: ui!

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.