Class: String
Instance Method Summary collapse
- #ends_with?(str) ⇒ Boolean
-
#exec(opts = {}) ⇒ Object
Executes the string with system * :background => true to run command in the background using & (currently only works on *nix systems) * :capture => true to capture the output.
- #false? ⇒ Boolean
-
#print ⇒ Object
Prints the String using print.
- #printn ⇒ Object
- #starts_with?(str) ⇒ Boolean
-
#to_range ⇒ Object
Parses a string like “1..10” to a Range.
- #true? ⇒ Boolean
Instance Method Details
#ends_with?(str) ⇒ Boolean
57 58 59 60 |
# File 'lib/darkext/string.rb', line 57 def ends_with?(str) str = str.to_s str == self[-str.length, str.length] end |
#exec(opts = {}) ⇒ Object
Executes the string with system
-
:background => true to run command in the background using & (currently only works on *nix systems)
-
:capture => true to capture the output. If :capture => true, background is voided
28 29 30 31 32 33 |
# File 'lib/darkext/string.rb', line 28 def exec(opts = {}) opts.with_defaults!(:background => false, :capture => false) return `#{self}` if opts[:capture] return fork { system(self) } if opts[:background] return system(self) end |
#false? ⇒ Boolean
48 49 50 |
# File 'lib/darkext/string.rb', line 48 def false? self.downcase == 'false' end |
#print ⇒ Object
Prints the String using print
36 37 38 |
# File 'lib/darkext/string.rb', line 36 def print Kernel.print(self) end |
#printn ⇒ Object
40 41 42 |
# File 'lib/darkext/string.rb', line 40 def printn Kernel.print(self + "\n") end |
#starts_with?(str) ⇒ Boolean
52 53 54 55 |
# File 'lib/darkext/string.rb', line 52 def starts_with?(str) str = str.to_s str == self[0, str.length] end |
#to_range ⇒ Object
Parses a string like “1..10” to a Range
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/darkext/string.rb', line 5 def to_range case self.count('.') when 2 elements = self.split('..') if elements[0] == elements[0].to_i.to_s return Range.new(elements[0].to_i, elements[1].to_i) else return Range.new(elements[0], elements[1]) end when 3 elements = self.split('...') if elements[0] == elements[0].to_i.to_s return Range.new(elements[0].to_i, elements[1].to_i, true) else return Range.new(elements[0], elements[1], true) end end raise ArgumentError.new('Could not parse range') end |
#true? ⇒ Boolean
44 45 46 |
# File 'lib/darkext/string.rb', line 44 def true? self.downcase == 'true' end |