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
a = ["Ferrari","Mercedes","BMW"] | |
a.cycle { |x| puts x } | |
# prints: Ferrari, Mercedes, BMW, Ferrari, Mercedes, BMW,.. forever. | |
a.cycle(2) { |x| puts x } | |
# prints: Ferrari, Mercedes, BMW, Ferrari, Mercedes, BMW. |
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
# The general structure of the cycle enumerable is as such: | |
cycle(n=nil){|obj| block} -> nil | |
# n = the number of times you want to cycle through the list of data. | |
# obj = object that is being passed into cycle. | |
# block = a block of code you wish to run onto the given object. | |
# An enumerator can be created as well: |
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 Bike | |
def initialize | |
@owner = "Nathan Park" | |
end | |
def wheel_size | |
@wheel = 26 | |
end | |
def bike_frame |
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
def tire_pressure # this is an example of an instance method | |
@psi = 100 # instance variables are signified with the @ symbol | |
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
// Example JavaScript Object | |
var skateboarder = { | |
name: "Rodney Mullen", | |
board: "Almost Deck", | |
wheels: "Spitfire", | |
trucks: "Independent" | |
}; | |
// The object must be initialized with the keyword "var" and contain the properties within the curley brackets. | |
// This example shows the object "skatboarder". |
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
// Add property to object | |
skateboarder.trick = "360 Flip"; | |
var skateboarder = { | |
name: "Rodney Mullen", | |
board: "Almost Deck", | |
wheels: "Spitfire", | |
trucks: "Independent", | |
trick: "360 Flip" // The new property trick is added here | |
}; |
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
// Delete property from object | |
delete skateboarder.trucks; | |
var skateboarder = { | |
name: "Rodney Mullen", | |
board: "Almost Deck", | |
wheels: "Spitfire", | |
trick: "360 Flip" // The old property trucks is deleted | |
}; |
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
grades = { | |
Jane: 89, | |
Bill: 88, | |
James: 95, | |
Jill: 94 | |
} |
OlderNewer