
-----------------------------------
wtd
Sun Jan 24, 2010 2:47 am

Random Ruby Ridiculousness
-----------------------------------
class Any
	def initialize(enum)
		@enum = enum
	end

	def ==(other)
		@enum.any? { |x| x == other }
	end
end

class All
	def initialize(enum)
		@enum = enum
	end

	def ==(other)
		@enum.all? { |x| x == other }
	end
end

module Enumerable
	def any
		Any.new self
	end

	def all
		All.new self
	end
end

if 

-----------------------------------
wtd
Sun Jan 24, 2010 2:53 am

RE:Random Ruby Ridiculousness
-----------------------------------
class Fixnum
	def even?
		self % 2 == 0
	end
end

class Any
	def initialize(enum)
		@enum = enum
	end

	def method_missing(symbol, *args)
		@enum.any? { |x| x.send(symbol, *args) }
	end
end

class All
	def initialize(enum)
		@enum = enum
	end

	def method_missing(symbol, *args)
		@enum.all? { |x| x.send(symbol, *args) }
	end
end

module Enumerable
	def any
		Any.new self
	end

	def all
		All.new self
	end
end

if 

-----------------------------------
Insectoid
Sun Jan 24, 2010 10:44 am

RE:Random Ruby Ridiculousness
-----------------------------------
I dunno what modules do, but I gather that you've made classes initialized by methods in a module which return boolean values from an expression. 

What I don't understand is what
[code]
def method_missing(symbol, *args) [/code] does, or why you don't pass parameters into All and Any's constructors.

-----------------------------------
Tony
Sun Jan 24, 2010 11:01 pm

RE:Random Ruby Ridiculousness
-----------------------------------

class Foo
   def method_missing(symbol, *args)
      puts "Foo is missing method '#{symbol}', with arguments '#{args}'"
   end
end

[code]
> Foo.new.bar "baz"
Foo is missing method 'bar', with arguments 'baz'
=> nil
[/code]

Any and All constructors _do_ get parameters, in a way that "baz" is a parameter in an above example. That is, parenthesis are not strictly necessary.

Recall that + is a method on Fixnum class.
[code]
> 1.+(2)
=> 3
[/code]
But we don't need to explicitly specify .method or (argument)

-----------------------------------
wtd
Sun Jan 24, 2010 11:37 pm

RE:Random Ruby Ridiculousness
-----------------------------------
Minor clean-up:

class Fixnum 
        def even? 
                self % 2 == 0 
        end 
end 

EnumerableWrapper = Struct.new :enum

class Any < EnumerableWrapper 
        def method_missing(symbol, *args) 
                @enum.any? { |x| x.send(symbol, *args) } 
        end 
end 

class All < EnumerableWrapper 
        def method_missing(symbol, *args) 
                @enum.all? { |x| x.send(symbol, *args) } 
        end 
end 

module Enumerable 
        def any 
                Any.new self 
        end 

        def all 
                All.new self 
        end 
end 

if 
