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
# coding: utf-8 | |
# Can ruby have method names have newlines/be crazy? | |
class BadKitty | |
FACE = " | |
|\\_/| | |
/ @ @ \\ | |
( > º < ) | |
`>>x<<´ |
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
The content |
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
The content |
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
The content |
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 Thing | |
include Mongoid::Document | |
field :integer_field, :type => Integer | |
field :big_decimal_field, :type => BigDecimal | |
field :date_field, :type => Date | |
end | |
thing = Thing.new |
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 Product | |
def list_price=(price) | |
write_price(:list_price, price) | |
end | |
def sales_price=(price) | |
write_price(:sales_price, price) | |
end | |
private |
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
require "open-uri" | |
loop do | |
begin | |
open("http://google.com", :read_timeout => 5) | |
rescue | |
puts "Timed out at #{Time.now}" | |
next | |
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
# Question 18A. What happens when the following is run? | |
lambda { |i,j| }.call(1,2,3) | |
# Question 18B. What happens when the following is run? | |
Proc.new { |i,j| }.call(1,2,3) |
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
# Question 15. What are the values of a, b, c and d? | |
a, (b, *c), d = 1, [2, 3, 4], 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
# Question 12. What does the following print (as of Ruby 1.9)? | |
thang = "biscuits" | |
[1,2,3].each { |n; thang| thang = n } | |
puts thang |
NewerOlder