arrayify!
Following from my post: Array.acts_like_array?, I can now implement arrayify without using is_a? Array or respond_to? :[] && !is_a? String
class Object
def arrayify
self.acts_like?(:array) ? self : [self]
end
end
So we can now do: thing = thing.arrayify or: do_something(thing.arrayify)
Now, what I really want to do is thing.arrayify!, but I'm not sure how to implement that. Any
Images:
- Add new comment
- 102 reads
- Feed: rubyglasses
- Original article


Recent comments
1 year 23 weeks ago
1 year 23 weeks ago
1 year 25 weeks ago
1 year 27 weeks ago
1 year 42 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 46 weeks ago
1 year 48 weeks ago