Jeff Schwab
6/27/2006 11:55:00 PM
Kenosis wrote:
> Doh! Grabbed the wrong edition of my Ruby manual. Oh well, look TWICE
> before you leap and check ri to be sure, comes to mind :)
>
> Ken
Honestly, I end up using hashes instead of proper sets a lot, anyway.
It's just the habit I picked up from years of Perl.
>
> Jeffrey Schwab wrote:
>> Just Another Victim of the Ambient Morality wrote:
>>> Hey, is there a Set object, like an Array or Hash object, in Ruby?
>>> So far, I've been using the Hash object and mapped the key to true.
>>> Then, I use the .include? method to determine if my "set" has the object,
>>> already. However, while reading a tutorial on Python, I noticed that it has
>>> a Set data type, which made me wonder if Ruby has one as well and, if not,
>>> why not?
>>> Thanks...
>> irb(main):001:0> require 'set'
>> => true
>> irb(main):002:0> s = Set.new
>> => #<Set: {}>
>> irb(main):003:0> s << 1
>> => #<Set: {1}>
>> irb(main):004:0> s << "hello"
>> => #<Set: {1, "hello"}>
>> irb(main):005:0> s << [2, 3, 5, 7]
>> => #<Set: {1, "hello", [2, 3, 5, 7]}>
>> irb(main):006:0> s
>> => #<Set: {1, "hello", [2, 3, 5, 7]}>
>> irb(main):007:0>
>>
>> Use "ri Set" for details.
>