Last active
August 29, 2015 14:22
-
-
Save sescobb27/0bb4398076ad8de7a6e5 to your computer and use it in GitHub Desktop.
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 'Welcome to RailsGirls Medellin!!!!' | |
# types | |
# - String | |
# - Boolean | |
# - Integer | |
# - Float | |
# - Array | |
# - Hash | |
a_string = "Hola" | |
a_nother_string = 'Hello World' | |
a_number = 200 | |
a_nother_number = 1_234_567 | |
a_float = 200.0 | |
an_array = [] | |
a_range = (1..10) | |
a_hash = {} # Dictionary | |
a_symbol = :simbol | |
a_nil = nil | |
PI = 3.1416 # Constant | |
PI = 1 # warning: already initialized constant PI | |
text1 = 'Holi' | |
text2 = 'From Rails' | |
text3 = 'Girls Medellin' | |
puts "#{text1} #{text2} #{text3}" | |
input = gets | |
puts "Look what you type: #{input}" | |
an_array.push 100 # => [100] | |
an_array.push 'string' # => [100, 'string'] | |
an_array.push {} # => [100, 'string', {}] | |
an_array.push Array.new # => [100, 'string', {}, []] | |
an_array.push 30.05 # => [100, 'string', {}, [], 30.05] | |
a_hash['Rails'] = 'Girls' # => {'Rails' => 'Girls'} | |
a_hash[:Colombia] = 'Medellin' # => {'Rails' => 'Girls', Colombia: 'Medellin'} | |
10.times do | |
puts "This year I will learn Ruby on Rails" | |
end | |
5.downto 0 do |x| | |
puts "#{x}!" | |
puts "Happy New Year!!!!(6 months late)" if x == 0 | |
end | |
[1,2,3,4,5,6].each do |number| | |
puts "#{number}^2 = #{number ** 2}" | |
end | |
(1..10).each do |n| | |
puts "user with id=(#{n}) ... " | |
end | |
# dictionaries | |
eng_msg = '' | |
es_msg = '' | |
{ | |
beer: 'pola', | |
party: 'fiesta', | |
after: 'despues', | |
workshop: 'taller' | |
}.each_pair do |english, spanish| | |
eng_msg += " #{english}" | |
es_msg += " #{spanish}" | |
end | |
puts eng_msg | |
puts es_msg | |
def weekend?(time) | |
time.saturday? || time.sunday? | |
end | |
if weekend? Time.now | |
puts "Let's Go Party!!!" | |
else | |
puts "workday :(" | |
end | |
class Person | |
attr_accessor :name, :age | |
def initialize name, age | |
@name = name | |
@age = age | |
end | |
def adult? | |
@age >= 18 | |
end | |
def life_time | |
case @age | |
when 0 .. 2 | |
puts "baby" | |
when 3 .. 6 | |
puts "little child" | |
when 7 .. 12 | |
puts "child" | |
when 13 .. 18 | |
puts "youth" | |
else | |
puts "adult" | |
end | |
end | |
end | |
kid = Person.new 'Yepeto', 15 # => Person.new('Yepeto', 15) | |
puts 'You can not enter here' unless kid.adult? | |
# THE SAME IN OTHER WAY | |
# ===== | |
# unless kid.adult? | |
# puts 'You can not enter here' | |
# end | |
# ===== | |
# if !kid.adult? | |
# puts 'You can not enter here' | |
# end | |
# ===== | |
kid.life_time # => youth |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is great @sescobb27! 👍
What do you think about adding some basic constructs so they can compare against the languages they already know:
if/else/switch
conditionals+, -, =, ==, *, ^
you can grab some of those from Ruby Fundamentals talk code