• 4 or 4.0 • Note that Fixnums and Floats are two separate subclasses of Numerics. Booleans • true or false Symbols • :green • Immutable. • Useful for representing an arbitrary value (use this where you want an enum or a String that represents an arbitrary value but isn’t displayed).
dynamically typed, so they can contain values of different types. • Arrays are more like what other languages call “lists”, since they can be modified. Ranges • 0..10 • Can be used to into into an array like this: array[0..10] Hashes • person = { “Name” => “Bob”, “Age” => 15 } • Like a dictionary or hash map in other languages. • person = { name: “Bob”, age: 15 } • name: “Bob” is the same as :name => “Bob”, but easier to read and write. • Looking up a value: person[:name]
@name = name end attr_reader :name def greet(other) puts “Hello #{other.name}, I am #{@name}.” end end # Create two people that will greet each other matz = Person.new(“Yukihiro Matsumoto”) david = Person.new(“David Heinemeier Hansson”) matz.greet(david) # output: Hello Yukihiro Matsumoto, I am David Heinemeier Hansson.