S
shasckaw
Hello,
when using tk, you can initialize tk objects with a block, example:
TkLabel.new(root) {
text 'Hello, World!'
pack { padx 15 ; pady 15; side 'left' }
}
text, pack, padx, ..., are used as commands instead of key of a hash. tk
objects allow to use a kind of ruby dialect, valid only in the context
of that object.
I would like to reproduce that technique but I don't find how. I have
already tried some code:
class Dialect
def initialize
yield
end
def add_some_stuff(stuff)
@stuff = stuff
end
def show
p @stuff
end
end
Dialect.new {add_some_stuff("Hello world!"); show}
It doesn't work, the interpreter (1.8.0) saying add_some_stuff doesn't
exist. I have also tried this:
class Dialect
def add_some_stuff(stuff)
@stuff = stuff
end
def show
p @stuff
end
end
var = Dialect.new
var.instance_eval {add_some_stuff("Hello world!"); show}
It works but it uses an explicit call of instance_eval which I don't
want to use. I have searched how to do the job the same way as with tk,
but I can't find! Can anyone help please?
Shasckaw
when using tk, you can initialize tk objects with a block, example:
TkLabel.new(root) {
text 'Hello, World!'
pack { padx 15 ; pady 15; side 'left' }
}
text, pack, padx, ..., are used as commands instead of key of a hash. tk
objects allow to use a kind of ruby dialect, valid only in the context
of that object.
I would like to reproduce that technique but I don't find how. I have
already tried some code:
class Dialect
def initialize
yield
end
def add_some_stuff(stuff)
@stuff = stuff
end
def show
p @stuff
end
end
Dialect.new {add_some_stuff("Hello world!"); show}
It doesn't work, the interpreter (1.8.0) saying add_some_stuff doesn't
exist. I have also tried this:
class Dialect
def add_some_stuff(stuff)
@stuff = stuff
end
def show
p @stuff
end
end
var = Dialect.new
var.instance_eval {add_some_stuff("Hello world!"); show}
It works but it uses an explicit call of instance_eval which I don't
want to use. I have searched how to do the job the same way as with tk,
but I can't find! Can anyone help please?
Shasckaw