RubyKin

Practice

What is the result of each of the following?

1) puts "What is the return result" + " of " + "this operation?"

2) "This string minus" - "That string"

3) "1234.55".to_i

4) "1234.55".to_f

5) "Not a number".to_i

6) puts "1\n2\n3\n"

7) Why might it be useful that the to_i (to integer) method return zero for strings that can’t be represented as numbers?

8) What do you think the length method does? "Count".length

9) How about the split method? "Count".split("")

10) What do you think slice does? "Count".slice(2)

Want to see more cool String methods? Just call methods on the String class! Type String.methods into your IRB:

IRB$ String.methods # some of the built-in Ruby methods for String

[:try_convert, :allocate, :new, :superclass, :freeze, :===, :==, :<=>, :<, :<=, :>, :>=, :to_s, :included_modules, :include?, :name, :ancestors, :instance_methods, :public_instance_methods, :protected_instance_methods, :private_instance_methods, :constants, :const_get, :const_

and many more...