Class: String
- Inherits:
-
Object
show all
- Defined in:
- lib/merb-core/core_ext/string.rb,
lib/merb-core/vendor/facets/inflect.rb
Defined Under Namespace
Classes: InvalidPathConversion
Instance Method Summary
collapse
Instance Method Details
Parameters
- o<String>
-
The path component to join with the string.
Returns
- String
-
The original path concatenated with o.
Examples
"merb"/"core_ext"
62
63
64
|
# File 'lib/merb-core/core_ext/string.rb', line 62
def /(o)
File.join(self, o.to_s)
end
|
#camel_case ⇒ Object
Returns
- String
-
The string converted to camel case.
Examples
"foo_bar".camel_case
30
31
32
|
# File 'lib/merb-core/core_ext/string.rb', line 30
def camel_case
split('_').map{|e| e.capitalize}.join
end
|
#escape_regexp ⇒ Object
Returns
- String
-
The string with all regexp special characters escaped.
Examples
"\*?{}.".escape_regexp
12
13
14
|
# File 'lib/merb-core/core_ext/string.rb', line 12
def escape_regexp
Regexp.escape self
end
|
#plural ⇒ Object
Also known as:
pluralize
#relative_path_from(other) ⇒ Object
66
67
68
|
# File 'lib/merb-core/core_ext/string.rb', line 66
def relative_path_from(other)
Pathname.new(self).relative_path_from(Pathname.new(other)).to_s
end
|
#singular ⇒ Object
Also known as:
singularize
#snake_case ⇒ Object
Returns
- String
-
The string converted to snake case.
Examples
"FooBar".snake_case
21
22
23
|
# File 'lib/merb-core/core_ext/string.rb', line 21
def snake_case
gsub(/\B[A-Z]/, '_\&').downcase
end
|
#to_const_path ⇒ Object
Returns
- String
-
The path that is associated with the constantized string, assuming a conventional structure.
Examples
"FooBar::Baz".to_const_path
50
51
52
|
# File 'lib/merb-core/core_ext/string.rb', line 50
def to_const_path
snake_case.gsub(/::/, "/")
end
|
#to_const_string ⇒ Object
Returns
- String
-
The path string converted to a constant name.
Examples
"merb/core_ext/string".to_const_string
39
40
41
|
# File 'lib/merb-core/core_ext/string.rb', line 39
def to_const_string
gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
end
|