class Object
Public Instance Methods
conversation() { || ... }
click to toggle source
# File lib/studio_game/iterators.rb, line 2 def conversation puts "Hello" yield puts "Goodbye" end
fizzbuzz(length)
click to toggle source
# File lib/studio_game/rubynotes.rb, line 60 def fizzbuzz(length) 1.upto(length) do |n| if n % 3 == 0 && n % 5 == 0 puts "FizzBuzz" elsif n % 5 == 0 puts "Buzz" elsif n % 3 == 0 puts "Fizz" else puts n end end end
gt_five(n)
click to toggle source
# File lib/studio_game/rubynotes.rb, line 32 def gt_five(n) n > 5 end
hello(name)
click to toggle source
# File lib/studio_game/rubynotes.rb, line 76 def hello(name) puts "Hello there #{name}!" end
max(n, x)
click to toggle source
# File lib/studio_game/rubynotes.rb, line 46 def max(n, x) n > x ? n : x end
mi_to_km(n)
click to toggle source
# File lib/studio_game/rubynotes.rb, line 39 def mi_to_km(n) n * 1.6 end
n_times(number) { |count| ... }
click to toggle source
# File lib/studio_game/iterators.rb, line 10 def n_times(number) 1.upto(number) do |count| yield count end end
show_triangle(n)
click to toggle source
# File lib/studio_game/rubynotes.rb, line 54 def show_triangle(n) 1.upto(n) { |length| puts "#" * length } end
sum(nums)
click to toggle source
# File lib/studio_game/rubynotes.rb, line 120 def sum(nums) nums.reduce(0) { |result, n| result + n } end