Created
July 5, 2017 02:41
-
-
Save forresty/d7050708f5d8da4e43061f6d3b5b6f88 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
| forrest_is_handsome && forrest_is_tall # => false | |
| forrest_is_handsome || forrest_is_tall # => true |
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
| # puts "Which action? [read|write|exit]" | |
| # action = gets.chomp | |
| # case action | |
| # when "read" | |
| # puts 'You are in READ mode' | |
| # when "write" | |
| # puts 'You are in WRITE mode' | |
| # when "exit" | |
| # puts 'Bye Bye' | |
| # when "read" | |
| # puts 'You are in READ mode AGAINNNNNN!' | |
| # else | |
| # puts 'Wrong action' | |
| # end | |
| Fixnum === object | |
| object = 123 | |
| case object | |
| when Fixnum | |
| puts "it is int" | |
| when String | |
| puts "it is string" | |
| end |
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
| sides = %w{ head tail } | |
| coin = sides.sample | |
| print "guess? > " | |
| guess = gets.chomp | |
| result = (guess == coin ? "win" : "lose") | |
| # result = if guess == coin | |
| # 'win' | |
| # else | |
| # 'lose' | |
| # end | |
| # if guess == coin | |
| # result = 'win' | |
| # else | |
| # result = 'lose' | |
| # end | |
| puts result |
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
| # for i in [1,2,3] | |
| # puts i | |
| # end | |
| # for i in (0..5) | |
| # puts i | |
| # end | |
| # [1,2,3].each do |i| | |
| # puts i | |
| # end | |
| (1..5).each do |i| | |
| puts i | |
| end | |
| # CRUD | |
| # | |
| # Create | |
| # Retrieve | |
| # Update | |
| # Delete |
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
| # num = 1 + rand(5) | |
| # print "your guess? > " | |
| # guess = gets.chomp.to_i | |
| # until num == guess | |
| # puts "try agains!" | |
| # print "your guess? > " | |
| # guess = gets.chomp.to_i | |
| # end | |
| # puts "you got it!" | |
| num = 1 + rand(5) | |
| # while true | |
| loop do | |
| print "your guess? > " | |
| guess = gets.chomp.to_i | |
| if num == guess | |
| puts "you got it!" | |
| # break | |
| else | |
| puts "try again!" | |
| end | |
| end | |
| # print "your guess? > " | |
| # guess = gets.chomp.to_i | |
| # if num == guess | |
| # puts "you got it!" | |
| # else | |
| # puts "try agains!" | |
| # end |
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
| def hello | |
| puts 'world' | |
| gjdosgjdosjgosgs | |
| end | |
| def gjdosgjdosjgosgs | |
| puts 'haha' | |
| end | |
| # hello |
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
| # hour = 23 | |
| # if hour < 12 | |
| # puts "Good morning!" | |
| # elsif hour >= 20 | |
| # puts "Good night!" | |
| # elsif hour > 12 | |
| # puts "Good afternoon!" | |
| # else | |
| # puts "Lunch time!" | |
| # end | |
| # def some_method(some_arg) | |
| # return nil if some_arg == nil | |
| # end | |
| # if !rainy | |
| # puts "go out!!!!!" | |
| # else | |
| # puts "stay inside!" | |
| # end |
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
| require_relative 'hello' | |
| hello |
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
| if false | |
| puts 'haha' | |
| end | |
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
| puts "how old are you?" | |
| # print "how old are you?\n" | |
| print '> ' | |
| age = gets.chomp.to_i | |
| if age >= 18 | |
| puts "you can vote now in Taiwan!" | |
| else | |
| puts "too young to vote.." | |
| end | |
| # array = [ | |
| # [1,2], | |
| # [3,4] | |
| # ] | |
| # # puts array | |
| # p array | |
| # array = [1, 2, 3, nil] | |
| # puts array | |
| # p array | |
| # puts nil | |
| # p nil | |
| # p array | |
| # print array | |
| # puts array.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment