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
# start prompt should prompt user to enter what they want to convert from and to | |
# prompt user for value to be converted | |
# display converted value | |
# display start prompt | |
@absolute_zero_in_celsius = -273.15 | |
@absolute_zero_in_fahrenheit = -459.67 | |
def quit | |
puts |
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
puts "Enter a year and I will tell you TRUE or FALSE, if that year is or is not a leap year." | |
print "> " | |
@year_choice = gets.chomp.to_i | |
leap_year_calculator = case | |
when @year_choice % 400 == 0 then true | |
when @year_choice % 100 == 0 then false | |
else @year_choice % 4 == 0 | |
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
s = "Welcome to the forum.\nHere you can learn Ruby.\nAlong with other members.\n" | |
def string_processor(non_split_string) | |
line_number = 0 | |
split_into_sentences = non_split_string.split(/\n/) | |
split_into_sentences.each do |sentence| | |
sentence.prepend("Line " + (line_number += 1).to_s + ": " ) | |
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
def start_program | |
puts "Soooo, what's new, sonny boy?" | |
gets_grandsons_input | |
end | |
def gets_grandsons_input | |
print "> " | |
@grandson_choice = gets.chomp | |
determines_if_grandma_heard | |
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
(1..100).each do |num| | |
if num % 3 == 0 && num % 5 == 0 | |
puts "FizzBuzz" | |
elsif num % 3 == 0 | |
puts "Fizz" | |
elsif num % 5 == 0 | |
puts "Buzz" | |
else | |
puts num | |
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
def method | |
a = 50 | |
puts a | |
end | |
a = 10 | |
method | |
puts a | |
=begin |
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 find_and_replace_files_existing_string_with_new_string(filename, old_string, new_string) | |
original_file_content = File.read("#{filename}") | |
new_file_content = original_file_content.gsub(old_string, new_string) | |
File.write("#{filename}", new_file_content) | |
end | |
=begin | |
Here is the existing sample file entitled 'plain_text.txt': | |
text text text text text |
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
# Returns the path to the current working directory, | |
# in the form of a string | |
Dir.getwd | |
# Creates a new working directory entitled 'tmp' within | |
# the current directory | |
Dir.mkdir("tmp") | |
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 find_and_replace(content, old_string, new_string) | |
@content_to_be_reset = content | |
if File.file?("#{content}") | |
@original_content = File.read("#{content}") | |
new_file_content = @original_content.gsub(old_string, new_string) | |
File.write("#{content}", new_file_content) | |
else | |
@original_content = content | |
new_file_content = @original_content.gsub(old_string, new_string) | |
# gsub is better for testing purposes |
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
s = 'key=value' | |
# arr = s.split("=") | |
s1, s2 = s.split("=")[0], s.split("=")[1] | |
#s1, s2 = arr[0], arr[1] | |
puts s1 #=> key | |
puts s2 #=> value |
OlderNewer