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

Version Path
primedia-endeca-0.9.0 lib/core_ext.rb
primedia-endeca-0.9.1 lib/core_ext.rb
primedia-endeca-0.9.10 lib/core_ext.rb
primedia-endeca-0.9.11 lib/core_ext.rb
primedia-endeca-0.9.12 lib/core_ext.rb
primedia-endeca-0.9.13 lib/core_ext.rb
primedia-endeca-0.9.14 lib/core_ext.rb
primedia-endeca-0.9.15 lib/core_ext.rb
primedia-endeca-0.9.16 lib/core_ext.rb
primedia-endeca-0.9.2 lib/core_ext.rb
primedia-endeca-0.9.3 lib/core_ext.rb
primedia-endeca-0.9.4 lib/core_ext.rb
primedia-endeca-0.9.5 lib/core_ext.rb
primedia-endeca-0.9.6 lib/core_ext.rb
primedia-endeca-0.9.7 lib/core_ext.rb
primedia-endeca-0.9.8 lib/core_ext.rb
primedia-endeca-0.9.9 lib/core_ext.rb