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
my_array = ["Apples", "Oranges", 67, ["hello","world"]] |
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
my_hash = {"Rent" => 2500, | |
"Car" => 279, | |
"Water" => 300, | |
"Utilities" => 300, | |
"Groceries" => 1500} |
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
my_array = ["Apples", "Oranges", 67, ["hello", "world"]] | |
my_array[0] | |
>> "Apples" | |
my_array[3] | |
>> ["hello", "world"] |
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
my_hash = {rent: 2500, | |
car: 279, | |
water: 300, | |
utilities: 300, | |
groceries: 1500} | |
my_hash[:car] | |
>> 279 | |
my_hash[:groceries] |
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
(0...15).group_by { |i| i % 3} | |
>> {0=>[0, 3, 6, 9, 12], 1=>[1, 4, 7, 10, 13], 2=>[2, 5, 8, 11, 14]} |
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
dogs = ["German Shepard", "Frech Bulldog", "Border Collie", "Great Dane", "Boxer", "Poodle", "Mut"] | |
>> ["German Shepard", "Frech Bulldog", "Border Collie", "Great Dane", "Boxer", "Poodle", "Mut"] | |
dogs.group_by { |dogs| dogs.length } | |
>> {14=>["German Shepard"], 13=>["Frech Bulldog", "Border Collie"], 10=>["Great Dane"], 5=>["Boxer"], 6=>["Poodle"], 3=>["Mut"]} |
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
dogs = ["German Shepard", "Frech Bulldog", "Border Collie", "Great Dane", "Boxer", "Poodle", "Mut"] | |
>> ["German Shepard", "Frech Bulldog", "Border Collie", "Great Dane", "Boxer", "Poodle", "Mut"] | |
dogs.group_by { rand(4) + 1} | |
# Result 1 | |
{4=>["German Shepard", "Border Collie", "Mut"], 3=>["Frech Bulldog"], 2=>["Great Dane", "Poodle"], 1=>["Boxer"]} | |
# Result 2 | |
{2=>["German Shepard", "Great Dane", "Poodle"], 1=>["Frech Bulldog", "Border Collie"], 4=>["Boxer"], 3=>["Mut"]} | |
# Result 3 | |
{2=>["German Shepard", "Border Collie", "Boxer", "Mut"], 3=>["Frech Bulldog", "Great Dane"], 1=>["Poodle"]} |
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
class Dog | |
end |
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
class Dog | |
def initialize(name, breed) | |
@name = name | |
@breed = breed | |
end | |
end | |
puppy = Dog.new('Atticus', 'German Shepherd') |
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
class Dog | |
def initialize(name, breed) | |
@name = name | |
@breed = breed | |
@hungry = false | |
end | |
def feed | |
puts "You just fed #{@name}, the #{@breed}." |
OlderNewer