Class methods
Shoes.app do
is not creating an instance, this is calling a class method.
This allows to call a method directly on a class, without having to instantiate it.
class Foo
def self.hello
puts "hello"
end
end
Foo.hello # outputs "hello"
Block parameter
The block form may confuse you, but it's an other ruby idiom that allows to pass chunk of logic to a method :
def yell( message, &block )
block.call( message.upcase )
end
yell( 'hello' ) do |message|
puts message
end
# outputs "HELLO"
DSL
Finally, there's a special form of block parameter often used to have good looking configuration : blocks that are evaluated in an other context.
When you call a block like in the previous example, the code inside blocks won't be able to access any private method or variable from the class where it's called ; it can only access what is in the scope of where the block was declared.
You can change that using #instance_eval
:
class Foo
def config( &block )
instance_eval &block
end
def write!
# perform some writing
end
end
foo = Foo.new
foo.config do
write! # this will work
end
So, basically, your shoes are doing a combination of those three concepts :)
This is not instantiating a class (although it probably does so behind the hood) and you don't especially need that, just use initialization as you are used to.