Sha256: 5a8d65f6e6df241c493a7caada4ab289bece5494e36bf057724b0c4f2e2b399e
Contents?: true
Size: 1.37 KB
Versions: 17
Compression:
Stored size: 1.37 KB
Contents
class Array def to_params join('&').to_params end end class Class def inherited_property(accessor, default = nil) instance_eval <<-RUBY, __FILE__, __LINE__ + 1 @#{accessor} = default def set_#{accessor}(value) @#{accessor} = value end alias #{accessor} set_#{accessor} def get_#{accessor} return @#{accessor} if instance_variable_defined?(:@#{accessor}) superclass.send(:#{accessor}) end RUBY # @path = default # # def set_path(value) # @path = value # end # alias_method path, set_path # def get_path # return @path if instance_variable_defined?(:path) # superclass.send(:path) # end end def inherited_accessor(accessor, default = nil) instance_eval <<-RUBY, __FILE__, __LINE__ + 1 class << self; attr_writer :#{accessor}; end @#{accessor} = default def #{accessor} return @#{accessor} if instance_variable_defined?(:@#{accessor}) superclass.send(:#{accessor}) end RUBY end end class Hash def to_params map { |k, v| if v.instance_of?(Hash) v.map { |sk, sv| "#{k}[#{sk}]=#{sv}" }.join('&') else "#{k}=#{v}" end }.join('&').to_params end end class NilClass def to_params '' end end class String def to_params URI.escape(self) end end
Version data entries
17 entries across 17 versions & 1 rubygems