duby
duby copied to clipboard
Closures blocking out the surrounding scope for classes/instances
An example, with the Android API:
hello = self
btn.setOnClickListener do
def onClick(v)
return if hello.txt.getText.toString.length == 0
hello.addMessage("hellotester", Hello(v.getContext).txt.getText.toString)
message = Bundle.new
message.putString("say", Hello(v.getContext).txt.getText.toString)
Message m = Message.obtain
m.setData(message)
hello.client.handler.sendMessage(m)
hello.txt.setText("")
end
end
hello is not accessible. Workaround here is to use Hello(v.getContext) (where Hello is the name of the class).