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
vagrant [vagrant]> irb | |
2.3.0 :001 > def say_hi(name) | |
2.3.0 :002?> "Hi, #{name}" | |
2.3.0 :003?> end | |
=> :say_hi | |
2.3.0 :004 > say_hi("Joanna") | |
=> "Hi, Joanna" | |
2.3.0 :005 > an_array = ['Hello', 'nurse', 'and', 'world'] | |
=> ["Hello", "nurse", "and", "world"] | |
2.3.0 :006 > an_array.each {|word| puts word} |
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 fizzbuzz_value(i) | |
if i % 15 == 0 | |
puts "FizzBuzz" | |
elsif i % 5 == 0 | |
puts "Buzz" | |
elsif i % 3 == 0 | |
puts "Fizz" | |
else | |
puts i | |
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
x = 1 | |
loop do | |
puts "What would you like to say to Shakil?" | |
say = gets.chomp.downcase | |
x = say.length | |
#If you pretend to be a dog and bark ("woof") at him, he will go a bit nuts and woof back at you three times, pretty loudly: "WOOF WOOF WOOF" | |
if say == "woof" | |
puts "WOOF WOOF WOOF" | |
# #If you explicitly use his name and tell him to stop (either "shakil stop" or "Shakil STOP!") he will not respond back with a bark (enjoy your moment of peace) |
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 maximum(arr) | |
n = arr.length | |
loop do | |
swapped = false | |
(n-1).times do |i| | |
if arr[i] > arr[i+1] | |
arr[i], arr[i+1] = arr[i+1], arr[i] | |
swapped = true | |
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
# must be baller and either furnished or rent cheaper than 2100 | |
def rent?(baller, furnished, rent) | |
if baller && (furnished || rent < 2100) | |
return true | |
else | |
return false | |
end | |
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
=begin | |
# Sort the array from lowest to highest | |
def sort(arr) | |
arr.sort | |
end | |
=end | |
def bubble_sort(arr) | |
n = arr.length |
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
@states = { | |
OR: 'Oregon', | |
FL: 'Florida', | |
CA: 'California', | |
NY: 'New York', | |
MI: 'Michigan', | |
} | |
@states.store(:NJ,'New Jersey') | |
@states.store(:AL,'Alabama') |
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 count_letters | |
puts "Tell me something" | |
phrase = gets.chomp | |
result = phrase.scan(/\w/) | |
hash = Hash.new(0) | |
result.inject(hash) {|key, value| | |
hash[value] += 1 |
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
list = {'yvr' => 'Vancouver', 'yba' => 'Banff', 'yyz' => 'Toronto', 'yxx' => 'Abbotsford', 'ybw' => 'Calgary'} | |
# Why is it returning nil instead of first element of the list above | |
p list['yvr'] | |
def average(numbers) |
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
require "pry" | |
@player1_points = 3 | |
@player2_points = 3 | |
@players = {player1: @player1_points, player2: @player2_points}.cycle | |
def whos_playing | |
puts "#{@current_player[0]}, your turn" |
OlderNewer