Sha256: 7e82d30a07a2588f7992acfc56a2492d7157c31c0854c16061d12510c80130f7

Contents?: true

Size: 663 Bytes

Versions: 5

Compression:

Stored size: 663 Bytes

Contents

# encoding: UTF-8
class SymbolOperator
  include Comparable

  attr_reader :field, :operator

  def initialize(field, operator, options={})
    @field, @operator = field, operator
  end unless method_defined?(:initialize)
  
  def <=>(other)
    if field == other.field
      operator <=> other.operator
    else
      field.to_s <=> other.field.to_s
    end
  end
  
  def ==(other)
    field == other.field && operator == other.operator
  end
end

class Symbol
  %w(gt lt gte lte ne in nin mod all size exists asc desc).each do |operator|
    define_method(operator) do
      SymbolOperator.new(self, operator)
    end unless method_defined?(operator)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
plucky-0.2.1 lib/plucky/extensions.rb
plucky-0.2 lib/plucky/extensions.rb
plucky-0.1.4 lib/plucky/extensions.rb
plucky-0.1.3 lib/plucky/extensions.rb
plucky-0.1.2 lib/plucky/extensions.rb