Skip to content

Instantly share code, notes, and snippets.

View fenixbrassi's full-sized avatar

Ernesto Ponce fenixbrassi

View GitHub Profile
@fenixbrassi
fenixbrassi / gist:8108403
Created December 24, 2013 03:26
Practicing with classes methods
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
@fenixbrassi
fenixbrassi / gist:8033869
Last active December 31, 2015 19:29
String practice
#strings practice
def longest_strings( param , n )
param.split(' ').sort_by(&:length).reverse.first(3)
end
puts "Give me the string"
words = gets.chomp
@fenixbrassi
fenixbrassi / gist:8033454
Created December 19, 2013 02:33
Hash Practice
#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
@fenixbrassi
fenixbrassi / gist:8015793
Created December 18, 2013 01:19
Array Example of usage
#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 = ""
@fenixbrassi
fenixbrassi / gist:8015638
Created December 18, 2013 01:02
Enumerable functions
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]
@fenixbrassi
fenixbrassi / gist:7998908
Last active December 31, 2015 14:18
Practicing with Arrays in Ruby on Rails
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]
@fenixbrassi
fenixbrassi / gist:7981877
Created December 16, 2013 03:27
The longes string
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
@fenixbrassi
fenixbrassi / gist:7981814
Created December 16, 2013 03:17
Palindrome
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"
@fenixbrassi
fenixbrassi / gist:7981402
Created December 16, 2013 02:09
Factorial
#factorial
def factorial(x)
if x <= 1
return 1
else
x * factorial(x - 1)
end
end
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