This file contains hidden or 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
# This method generates a multiplication table. | |
class Table | |
def generate_table( | |
table_size, | |
title = '', | |
decoration = '' | |
) | |
result = '' | |
heading = "Times table to #{table_size}\n" |
This file contains hidden or 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
# This method generates a multiplication table. | |
class Table | |
def generate_table(x, y='y', z='y') | |
# set up parameters for table | |
arr2 = arr1 = (1..x).to_a | |
col_size = (arr2[-1] * arr2[-1]).to_s.size | |
table = "" | |
border = 0 | |
length = "" |
This file contains hidden or 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 kelvin_to_rankine(value) | |
value * 1.8 | |
end | |
def rankine_to_kelvin(value) | |
value / 1.8 | |
end | |
def rankine_to_celcius(value) | |
value_holder = rankine_to_kelvin(value) |
This file contains hidden or 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
# doctest: correct output | |
# >> split_message("Welcome to the forum.\nHere you can learn Ruby.\n"\ | |
# "Along with other members.\n") | |
# => ["Line 1: Welcome to the forum.", "Line 2: Here you can learn Ruby.", "Line 3: Along with other members."] | |
def split_message(message) | |
message.split("\n").collect.with_index { |i, j| "Line #{j + 1}: " + i } | |
end | |
split_message("Welcome to the forum.\nHere you can learn Ruby.\n"\ |
This file contains hidden or 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 addstring(x,y) | |
z = x + y | |
return z | |
end | |
def putstring(x,y) | |
z = x + y | |
puts z | |
end |
This file contains hidden or 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
# doctest: get ternary equivalent when true | |
# >> ternary(3 > 1,"hello",3) | |
# => "hello" | |
# doctest: get ternary equivalent when false | |
# >> ternary(3 < 1,"hello",3) | |
# => 3 | |
def ternary(statement, true_result, false_result) | |
(true_result if statement == true) || | |
(false_result if statement == false) |
This file contains hidden or 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
# prints line numbers before each line & aligns the ":" | |
class ListGenerator | |
def column_alignment(lines) | |
lines.map.with_index(1) do |output, line_number| | |
"Line #{number_spacing(lines, line_number)}#{line_number}:"\ # rewrite method calls | |
"#{line_spacing(output, lines)}#{output}" # rewrite method calls | |
end | |
end |
This file contains hidden or 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 split_message(message) | |
output_line = "" | |
message.each_line.with_index(1) do |line, index| | |
output_line << "Line #{index}: #{line}" | |
end | |
output_line | |
end |
This file contains hidden or 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
# no "if" statement | |
def ternary(statement, true_result, false_result) | |
(true && statement) && true_result || false_result | |
end |
This file contains hidden or 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
# prints line numbers before each line & aligns the ":" | |
class ListGenerator | |
def column_alignment(lines) | |
lines = lines.split("\n") | |
lines.map.with_index(1) do |output, line_number| | |
"Line #{number_spacing(lines, line_number)}#{line_number}: "\ | |
"#{output}" | |
end |