Sha256: c07cc02c33107defd428d3073f0e0a3f09bea20c144abb78a24b1458123affd5
Contents?: true
Size: 1.83 KB
Versions: 5
Compression:
Stored size: 1.83 KB
Contents
=begin rdoc Basic, add an alias_method to the object class Add returning to the object =end class Object def my_methods self.methods.sort - (self.class.methods + self.class.superclass.methods) end def to_os self end def alias_method(new_id, original_id) original = self.method(original_id).to_proc define_method(new_id){|*args| original.call(*args)} end def with_options(opts={}, parent=self, &block) @p = parent.clone @p.options.merge!(opts) @p.instance_eval &block if block end def returning(receiver) yield receiver receiver end def extended(&block) block.in_context(self).call self end def send_if_method(v, *args) if (v.nil? || v.to_s.empty? || v.is_a?(Array) || v.is_a?(Integer)) v else vs = v.to_s.to_sym respond_to?(vs) ? self.send(vs, *args) : v end end def to_option_string case self.class when String self.to_option_string when Array self.each {|a| a.to_option_string }.join(" ") else "#{self}" end end def block_instance_eval(*args, &block) return instance_eval(*args,&block) unless block_given? && !block.arity.zero? old_method = (self.class.instance_method(:__) rescue nil) self.class.send(:define_method, :__, &block) block_method = self.class.instance_method(:__) if old_method self.class.send(:define_method, :__, old_method) else self.class.send(:remove_method, :__) end block_method.bind(self).call(*args) end def meta_def name, &blk meta_eval { define_method name, &blk } end def meta_undef name meta_eval { remove_method name } end def run_in_context(&block) name="temp_#{self.class}_#{parent.to_s}".to_sym meta_def name, &block self.send name, self # self.instance_eval &block if block meta_undef name end end
Version data entries
5 entries across 5 versions & 1 rubygems