This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
book = { "author" => "J.K. Rowling", | |
"title" => "Harry Potter and the Philosopher's Stone", | |
"isbn" => "9788478888566"} | |
book.each {|key, value| puts "#{key} is #{value}"} | |
# => author is J.K. Rowling | |
# => title is Harry Potter and the Philosopher's Stone | |
# => isbn is 9788478888566 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
empty_hash = Hash.new # => {} | |
default_hash = Hash.new("Harry Potter and the Philosopher's Stone") | |
empty_hash["book"] # => nil | |
default_hash["book"] # => "Harry Potter and the Philosopher's Stone" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
book = { "author" => "J.K. Rowling", | |
"title" => "Harry Potter and the Philosopher's Stone", | |
"isbn" => "9788478888566"} | |
book["author"] # => "J.K. Rowling" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
book = { author: "J.K. Rowling", | |
title: "Harry Potter and the Philosopher's Stone", | |
isbn: "9788478888566"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
book = { "author" => "J.K. Rowling", | |
"title" => "Harry Potter and the Philosopher's Stone", | |
"isbn" => "9788478888566"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
evens = [2, 4, 6, 8] | |
evens.map { |even| even*2 } | |
# => [4, 8, 12, 16] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
authors = ["Arthur Conan Doyle", "J.K. Rowling", "J.R.R. Tolkien", "Hanif Kureishi"] | |
authors.push("Neil Gaiman") | |
authors # => ["Arthur Conan Doyle", | |
# "J.K. Rowling", | |
# "J.R.R. Tolkien", | |
# "Hanif Kureishi", | |
# "Neil Gaiman"] | |
authors.pop() | |
authors # => ["Arthur Conan Doyle", | |
# "J.K. Rowling", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
authors = ["Arthur Conan Doyle", "J.K. Rowling", "J.R.R. Tolkien", "Hanif Kureishi"] | |
authors[-4] # => "Arthur Conan Doyle" | |
authors[-3] # => "J.K. Rowling" | |
authors[-2] # => "J.R.R. Tolkien" | |
authors[-1] # => "Hanif Kureishi" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
authors = ["Arthur Conan Doyle", "J.K. Rowling", "J.R.R. Tolkien", "Hanif Kureishi"] | |
authors[0] # => "Arthur Conan Doyle" | |
authors[1] # => "J.K. Rowling" | |
authors[2] # => "J.R.R. Tolkien" | |
authors[3] # => "Hanif Kureishi" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
authors = ["Arthur Conan Doyle", "J.K. Rowling", "J.R.R. Tolkien", "Hanif Kureishi"] |
NewerOlder