Skip to content

Instantly share code, notes, and snippets.

@chischaschos
Created May 22, 2012 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chischaschos/2770412 to your computer and use it in GitHub Desktop.
Save chischaschos/2770412 to your computer and use it in GitHub Desktop.
module B
def greeting
puts "Hi there"
end
end
module C
def yell
puts "AAaaaaaaaaa!!"
end
end
class A
extend B
include C
end
A.greeting
A.new.yell
class D; end
D.extend B
D.send :include, C
D.greeting
D.new.yell
class B
def greeting
puts "holaaaaa"
end
end
class A < B
end
A.new.greeting
# Re open A class
class A
def greeting
puts "The new hoolaaaaaa"
end
end
A.new.greeting
proc1 = lambda { puts "Created as a lambda" }
proc2 = Proc.new do
puts "Created as a proc"
end
proc1.call
proc2.call
def greeting a_proc
a_proc.call
end
greeting proc1
greeting proc2
proc1 = lambda { |name| puts "Hi #{name}" }
proc2 = Proc.new do |name|
puts "Hi #{name}"
end
proc1.call "Juan"
proc2.call "Pepe"
def greeting a_proc, name
a_proc.call name
end
greeting proc1, "Peca"
def greeting name
puts "Inside the greeting before yielding"
yield name
puts "Inside the greeting after yielding"
end
greeting "Maria" do |name|
puts "Greeting #{name}"
end
class Configuration
attr_accessor :username, :password
def initialize
yield self
end
end
c = Configuration.new do |config|
config.username = 'juan'
config.password = '123'
end
puts c.username
puts c.password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment