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 Employee | |
attr_accessor :first_name, :last_name, :salary, :age, :months_of_service | |
def initialize(first_name , last_name, salary, age, months_of_service) | |
@first_name = first_name | |
@last_name = last_name | |
@salary = salary | |
@age = age | |
@months_of_service = months_of_service | |
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
#strings practice | |
def longest_strings( param , n ) | |
param.split(' ').sort_by(&:length).reverse.first(3) | |
end | |
puts "Give me the string" | |
words = gets.chomp |
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
#hash | |
student = {} | |
student["First Name"] = “John” | |
student["Last Name"] = “Doe” | |
student["Age"] = 15 | |
student["Subjects"] = {} | |
student["Subjects"][“Physics”] = 75 | |
student["Subjects"][”Chemistry”] = 98 | |
student["Subjects"][”Maths”] = 85 |
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
#Write a program that asks user to type as many words as he/she wants. | |
#One word per line, continuing until the user presses enter on an empty line. The output of the program should be the words in alphabetical order. | |
def order_string(paragraph) | |
end | |
puts " Tell me a story " | |
story = "" |
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
irb(main):054:0> [].any? | |
=> false | |
irb(main):055:0> [2].any? | |
=> true | |
irb(main):058:0> [2,2,3,4,5,6,7].count | |
=> 7 | |
irb(main):061:0> [2,2,3,4,5,6,7].drop(1) | |
=> [2, 3, 4, 5, 6, 7] |
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
irb(main):001:0> [1,1,1] - [1] | |
=> [] | |
irb(main):002:0> [1,2,3,5].delete(5) | |
=> 5 | |
irb(main):003:0> [1,2,3,5].delete_at(2) | |
=> 3 | |
irb(main):004:0> [1,2,3,5].pop(1) | |
=> [5] | |
irb(main):005:0> [1,2,3,5].pop(8) | |
=> [1, 2, 3, 5] |
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 give_the_longest(array_strings) | |
longest_string = "" | |
array_strings.split(',').each do |x| | |
if x.length > longest_string.length | |
longest_string = x | |
end | |
end | |
longest_string | |
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 is_a_palindrome?(str) | |
str.to_s.chomp == str.to_s.chomp.reverse | |
end | |
puts " give me a word" | |
w = gets | |
puts (is_a_palindrome? w) ? "Is a Palindrome": "Is not | |
a Palindrome" |
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
#factorial | |
def factorial(x) | |
if x <= 1 | |
return 1 | |
else | |
x * factorial(x - 1) | |
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 give_greates_common_divisor(x,y) | |
x.to_i.gcd(y.to_i) | |
end | |
puts "Give the first number" | |
x = gets | |
puts "Give the second number" | |
y = gets | |
NewerOlder