Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Ruby decorator

ruby decorator scrolledwindow method_missing

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 serpent

serpent

    CC Regular

  • Member
  • PipPipPip
  • 30 posts

Posted 16 August 2013 - 02:28 AM

Hello,

I want to write decorator which embed given gtk widget inside ScrolledWindow. I've written this code:

 

class ScrollingDecorator < Gtk::ScrolledWindow
	def initialize(widget, width, height, *args)
		@widget=widget
		super(*args)
		set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC).set_size_request(width, height);
		add(@widget);
	end

	def method_missing(method, *args)
		@widget.send(method, *args)
	end

	def respond_to?(method)
		return @categories.respond_to?(method)
	end
end

 

I'd like to know whether there is better way of writing decorator in ruby. I've read that using method_missing should be avoided as it causes performance penalty. 

Edited by Roger, 16 August 2013 - 07:38 AM.
title and tag