superators 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/superators/macro.rb +5 -5
- data/lib/superators/version.rb +1 -1
- data/spec/superator_spec.rb +16 -0
- metadata +2 -2
    
        data/lib/superators/macro.rb
    CHANGED
    
    | @@ -13,7 +13,7 @@ module SuperatorMixin | |
| 13 13 | 
             
                if respond_to_superator? sup
         | 
| 14 14 | 
             
                  __send__ superator_definition_name_for(sup), operand
         | 
| 15 15 | 
             
                else
         | 
| 16 | 
            -
                  raise  | 
| 16 | 
            +
                  raise NoMethodError, "Superator #{sup} has not been defined on #{self.class}"
         | 
| 17 17 | 
             
                end
         | 
| 18 18 | 
             
              end
         | 
| 19 19 |  | 
| @@ -29,7 +29,7 @@ module SuperatorMixin | |
| 29 29 |  | 
| 30 30 | 
             
              def superator(operator, &block)
         | 
| 31 31 | 
             
                raise ArgumentError, "block not supplied" unless block_given?
         | 
| 32 | 
            -
                raise  | 
| 32 | 
            +
                raise ArgumentError, "Not a valid superator!" unless superator_valid?(operator)
         | 
| 33 33 |  | 
| 34 34 | 
             
                real_operator = real_operator_from_superator operator
         | 
| 35 35 |  | 
| @@ -46,7 +46,7 @@ module SuperatorMixin | |
| 46 46 | 
             
                  # When we get to the method defining, we have to know whether the superator had to be aliased
         | 
| 47 47 | 
             
                  # or if it's new entirely.
         | 
| 48 48 | 
             
                  define_method(real_operator) do |operand|
         | 
| 49 | 
            -
                    if operand.kind_of?  | 
| 49 | 
            +
                    if operand.kind_of?(SuperatorFlag) && operand.superator_queue.any?
         | 
| 50 50 | 
             
                      sup = operand.superator_queue.unshift(real_operator).join
         | 
| 51 51 | 
             
                      operand.superator_queue.clear
         | 
| 52 52 |  | 
| @@ -56,7 +56,7 @@ module SuperatorMixin | |
| 56 56 | 
             
                      if respond_to? alias_for_real_method
         | 
| 57 57 | 
             
                        __send__(alias_for_real_method, operand)
         | 
| 58 58 | 
             
                      else
         | 
| 59 | 
            -
                        raise  | 
| 59 | 
            +
                        raise NoMethodError, "undefined method #{real_operator} for #{operand.inspect}:#{operand.class}"
         | 
| 60 60 | 
             
                      end
         | 
| 61 61 | 
             
                    end
         | 
| 62 62 | 
             
                  end
         | 
| @@ -77,7 +77,7 @@ module SuperatorMixin | |
| 77 77 | 
             
                      end
         | 
| 78 78 | 
             
                    end
         | 
| 79 79 | 
             
                  else
         | 
| 80 | 
            -
                    raise  | 
| 80 | 
            +
                    raise NoMethodError, "undefined superator #{sup} for #{self.inspect}:#{self.class}"
         | 
| 81 81 | 
             
                  end
         | 
| 82 82 | 
             
                end
         | 
| 83 83 | 
             
              end
         | 
    
        data/lib/superators/version.rb
    CHANGED
    
    
    
        data/spec/superator_spec.rb
    CHANGED
    
    | @@ -54,6 +54,7 @@ describe "The 'superator' macro" do | |
| 54 54 | 
             
                end.new
         | 
| 55 55 | 
             
                lambda { victim <<   Object.new }.should throw_symbol(:original_method)
         | 
| 56 56 | 
             
                lambda { victim <<~~ Object.new }.should throw_symbol(:superator)
         | 
| 57 | 
            +
                
         | 
| 57 58 | 
             
              end
         | 
| 58 59 |  | 
| 59 60 | 
             
              # This one is going to be very difficult to implement. method_added() maybe?
         | 
| @@ -67,6 +68,20 @@ describe "The 'superator' macro" do | |
| 67 68 | 
             
                lambda { victim.new() <~~ Object.new }.should throw_symbol(:superator)
         | 
| 68 69 | 
             
              end
         | 
| 69 70 |  | 
| 71 | 
            +
              it "should allow the 'real' operator to be called within the superator definition" do
         | 
| 72 | 
            +
                victim = "Super"
         | 
| 73 | 
            +
                class << victim
         | 
| 74 | 
            +
                  superator "++" do |operand|
         | 
| 75 | 
            +
                    upcase + operand.upcase
         | 
| 76 | 
            +
                  end
         | 
| 77 | 
            +
                  superator "-~+~-" do |operand|
         | 
| 78 | 
            +
                    self + operand
         | 
| 79 | 
            +
                  end
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
                (victim ++ "ators").should == "SUPERATORS"
         | 
| 82 | 
            +
                lambda { victim -~+~- "man" }.should_not raise_error
         | 
| 83 | 
            +
              end
         | 
| 84 | 
            +
              
         | 
| 70 85 | 
             
            end
         | 
| 71 86 |  | 
| 72 87 | 
             
            describe "Defined binary superators" do
         | 
| @@ -99,6 +114,7 @@ describe "Defined binary superators" do | |
| 99 114 | 
             
                  end.new <--- Object.new
         | 
| 100 115 | 
             
                end.should throw_symbol(:last)
         | 
| 101 116 | 
             
              end
         | 
| 117 | 
            +
             | 
| 102 118 | 
             
            end
         | 
| 103 119 |  | 
| 104 120 | 
             
            describe "The superator_send method" do
         | 
    
        metadata
    CHANGED
    
    | @@ -3,8 +3,8 @@ rubygems_version: 0.9.4 | |
| 3 3 | 
             
            specification_version: 1
         | 
| 4 4 | 
             
            name: superators
         | 
| 5 5 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 6 | 
            -
              version: 0.9. | 
| 7 | 
            -
            date: 2007-08- | 
| 6 | 
            +
              version: 0.9.1
         | 
| 7 | 
            +
            date: 2007-08-29 00:00:00 -07:00
         | 
| 8 8 | 
             
            summary: Superators add new sexy operators to your Ruby objects.
         | 
| 9 9 | 
             
            require_paths: 
         | 
| 10 10 | 
             
            - lib
         |