On Friday 17 January 2003 07:08 am, Bulat Ziganshin wrote:
> i dont know. on the my side, i like 'when NACK' idea - may be because
> it is close to pattern matching (in functional programming). in one
> program i used 3rd variant, smth like:

i agree, nack would be good. i suppose returning nil if the method doesn't 
exist is out of the question?

> def f(arr)  # arr may be Array or nil
>   arr.flatten.size || 0
> end
>
> class NilClass
>   def flatten
>     nil
>   end
>   def size
>     nil
>   end
> end

ah, yes, you know i already have added a to_s method to the NilClass to ease 
things on that end. hmmm...you gave me an idea. perhaps this:

# x is a symbol
def has_value?(x)
	return nil if not self.respond_to?(x)
	case send(x)
	when nil, false, 0, 0.0, '', [], {}
		return false
	else
		return true
	end
end

but where would it go? Kernel?

-- 
tom sawyer, aka transami
transami / transami.net