Hi,
In message "[ruby-talk:4809] Some questions"
on 00/09/07, Friedrich Dominicus <frido / q-software-solutions.com> writes:
|- is there a reason why there isn't a each_index in String?
Because String is not a indexed container. You can use
each_with_index instead.
|- does Ruby do not provide some sort of List (I know Array are quite
|good enough, just wondering)
You mean linked list? No, but it's easy to define your own list class.
Here's the lisp style simple example.
class Cons
def initialize(car,cdr=nil)
@car = car
@cdr = cdr
end
attr_accessor :car, :cdr
def to_s
if @cdr == nil
"(#{@car})"
else
"(#{@car} #{@cdr})"
end
end
alias inspect to_s
def Cons::list(*args)
if args.size == 0
nil
else
Cons::new(args.shift, Cons::list(*args))
end
end
end
p Cons::list
p Cons::list(1,2,3,4)
matz.