stdlib/string/new_methods_parens.rb

tests/_examples/stdlib/string/new_methods_parens.rb in the metorex repository.

# to_i
puts "42".to_i
puts "  99  ".to_i
puts "hello".to_i
puts "-7".to_i
puts "3abc".to_i

# to_f
puts "3.14".to_f
puts "hello".to_f
puts "-2.5".to_f

# dup
s = "original"
d = s.dup
puts d

# gsub
puts "hello world".gsub("o", "0")
puts "aaa".gsub("a", "bb")

# sub (replace first only)
puts "hello hello".sub("hello", "hi")

# empty?
puts "".empty?
puts "hi".empty?

Output:

42
99
0
-7
3
3.14
0.0
-2.5
original
hell0 w0rld
bbbbbb
hi hello
true
false