Created
March 28, 2020 21:22
-
-
Save fernandozamoraj/f3e45e861edd89f00841c51c1008c6e6 to your computer and use it in GitHub Desktop.
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 is a comment | |
#this is an array assignment | |
numbers = [0,1,2,3,4,3,5,6,7,8] | |
#this is an array assignment from a range | |
puts "*****Numbers******" | |
numbers.each{|number| puts number} | |
puts "****Even numbers******" | |
numbers.each do |number| | |
puts number if number % 2 == 0 | |
end | |
#odd | |
numbers.each{|number| puts number if number%2!=0 } | |
puts "Unique Numbers" | |
numbers.uniq.each{|number| puts number} | |
puts "*****Person Hash****" | |
person = {name: "joe", age: 22, url: "url1", shorturl: "short url"} | |
puts person | |
puts person[:name] | |
puts "******person.each if they contain prop url*******" | |
person.each{ |key, value| puts "#{key}: #{value}" if "#{key}".include?("url")} | |
puts "********methods********" | |
"joe".methods.each { |method| puts method if "#{method}".include?"sum"} | |
puts "********get input********" | |
puts "What is your name?" | |
#name = gets.chomp | |
puts "***default return using area example****" | |
def area(w,h) | |
w*h | |
end | |
puts "area of w:#{10} h: #{5} #{area(10,5)}" | |
puts "*****Classes Using Person******" | |
class Person | |
attr_accessor :first_name, :last_name | |
def initialize(first_name, last_name) | |
@first_name = first_name | |
@last_name = last_name | |
end | |
def to_s | |
"#{@first_name} #{@last_name}" | |
end | |
end | |
person = Person.new("John", "Smith") | |
person.first_name = "Mike" | |
puts "person.first_name: #{person.first_name}" | |
puts "person: #{person}" | |
puts "*****mapped*********" | |
mapped = [1,2,3].map{|item| "item: #{item}"} | |
puts mapped | |
puts "******array from range*******" | |
array_from_range = (0..10).to_a() | |
puts array_from_range | |
puts "******for loop******" | |
for i in 0..5 | |
puts i | |
end | |
puts "***** if elsif******" | |
if true && true | |
puts "true and true" | |
elsif true || false | |
puts "will never reach this" | |
else | |
puts "never here" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment