Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Using closures, continuations in real life
Fefo
3/5/2007 2:04:00 AM
Hi all !! I'm fairly new to Rails programming and finding somewhat
different n the approach than .NET programming I did previosuly. I
found this blog post :
http://deadprogrammersociety.blogspot.com/2007/02/ruby-blocks-closures-and-continua...
It's about closures and contiinuations, I get the basic idea about
closures for example
class GreetingGenerator
def initialize(greeting)
@block = lambda {|name| puts "#{greeting}, #{name}"}
end
def greet(name)
@block.call name
end
end
frenchGreeting = GreetingGenerator.new "Bonjour"
englishGreeting = GreetingGenerator.new "Hello"
southernGreeting = GreetingGenerator.new "Howdy"
japaneseGreeting = GreetingGenerator.new "Ohayou"
germanGreeting = GreetingGenerator.new "Guten Tag"
frenchGreeting.greet "John"
englishGreeting.greet "John"
southernGreeting.greet "John"
japaneseGreeting.greet "John"
germanGreeting.greet "John"
puts greeting # just checking that the `greeting` variable doesn't
exist in the main scope
In this case, each block carries a little information with it
("greeting").
This gives me the idea that clousures might be used in practice as a
functional replacement for a class behaving as an abstract factory
(the pattern). In this example the function makes a closure over the
type of language (i.e. english, german) and then we pass to each
function the parameters for the fabric to produce the output.
Could anyone post some more comments and tell me if this idea is OK? I
would love to know about continuations also. !
Thanks & regards
Federico
Espero sus opiniones y comentarios tambien sobre por ejemplo
continuations.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Using closures, continuations in real life
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password