Class: String
- Defined in:
- lib/zucker/case.rb,
lib/zucker/unary.rb,
lib/zucker/union.rb,
lib/zucker/string.rb,
lib/zucker/aliases.rb
Instance Method Summary collapse
- #+@ ⇒ Object
- #-(rem) ⇒ Object
- #-@ ⇒ Object
- #^(pos) ⇒ Object
-
#constantize(default_value = nil) ⇒ Object
always uses global scope as in AS…
- #lchomp(arg = $/) ⇒ Object
- #lchomp!(arg = $/) ⇒ Object
- #ords ⇒ Object
- #to_camel ⇒ Object
- #to_snake ⇒ Object
- #|(arg) ⇒ Object
Instance Method Details
#+@ ⇒ Object
5 6 7 |
# File 'lib/zucker/unary.rb', line 5 def +@ self end |
#-(rem) ⇒ Object
5 6 7 |
# File 'lib/zucker/string.rb', line 5 def -(rem) gsub( Regexp === rem ? rem : rem.to_s, '' ) end |
#-@ ⇒ Object
9 10 11 |
# File 'lib/zucker/unary.rb', line 9 def -@ to_sym end |
#^(pos) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/zucker/string.rb', line 9 def ^(pos) pos = pos.to_i if pos >= 0 self[pos..-1] else self[0...pos] end end |
#constantize(default_value = nil) ⇒ Object
always uses global scope as in AS… is this good?
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/zucker/string.rb', line 31 def constantize(default_value = nil) # always uses global scope as in AS... is this good? get_constant = lambda{ self.split(/::/).inject( Object ){ |base_constant, current_constant| base_constant.const_get current_constant } } if !default_value && !block_given? get_constant.call else begin get_constant.call rescue NameError if block_given? yield self else default_value end end end end |
#lchomp(arg = $/) ⇒ Object
18 19 20 |
# File 'lib/zucker/string.rb', line 18 def lchomp(arg = $/) reverse.chomp(arg).reverse end |
#lchomp!(arg = $/) ⇒ Object
22 23 24 |
# File 'lib/zucker/string.rb', line 22 def lchomp!(arg = $/) reverse.chomp!(arg).reverse end |
#ords ⇒ Object
26 27 28 29 |
# File 'lib/zucker/string.rb', line 26 def ords unpack 'C*' # bytes.to_a end |
#to_camel ⇒ Object
9 10 11 |
# File 'lib/zucker/case.rb', line 9 def to_camel gsub(/(?:^|_)([a-z])/) do $1.upcase end end |
#to_snake ⇒ Object
5 6 7 |
# File 'lib/zucker/case.rb', line 5 def to_snake gsub(/(?<!^)[A-Z]/) do "_#$&" end.downcase end |