12. class You
def self.hello You.hello # hello
puts “hello” you = You.new
end you.hello # error
you.morning # morning
def morning
puts “morning”
end
end
12
13. a = 120
a = 100 if a == 100
if a == 100 puts "100!"
puts "100!" elsif a == 120
else puts "120!"
puts "not 100!" else
end puts “?”
end
13
14. list = [1,2,3] list = [1,2,3]
list.each do |it| list.each { |it|
puts it puts it
end }
14
15. "a".twice # error class You
private
class String def secret
def twice puts “sleeping”
self + self end
end end
end you = You.new
you.secret # error
"a".twice # => "aa' you.send(:secret) # =>
sleeping
15
26. class Blog < ActiveRecord::Base
end
class CreateBlogs < ActiveRecord::Migration
def self.up
>> entry = Blog.first create_table :blogs do |t|
>> entry.title t.string :title
t.text :body
t.timestamps
end
end
end
26