[#863] RDtool-0.5.0 — Toshiro Kuwabara <toshirok@...3.so-net.ne.jp>
Hi,
18 messages
1999/10/23
[#864] Re: RDtool-0.5.0
— matz@... (Yukihiro Matsumoto)
1999/10/26
Hi,
[#865] Re: RDtool-0.5.0
— Toshiro Kuwabara <toshirok@...3.so-net.ne.jp>
1999/10/26
Hi,
[#866] Re: RDtool-0.5.0
— matz@... (Yukihiro Matsumoto)
1999/10/26
Hi,
[#892] Re: RDtool-0.5.0
— Toshiro Kuwabara <toshirok@...3.so-net.ne.jp>
1999/10/31
Hi,
[#894] Re: RDtool-0.5.0
— matz@... (Yukihiro Matsumoto)
1999/11/01
Hi,
[#905] Re: RDtool-0.5.0
— Toshiro Kuwabara <toshirok@...3.so-net.ne.jp>
1999/11/04
Hi,
[#906] Re: RDtool-0.5.0
— matz@... (Yukihiro Matsumoto)
1999/11/04
Hi,
[#907] Re: RDtool-0.5.0
— Kazuhiro HIWADA <hiwada@...>
1999/11/04
Hi,
[#908] Re: RDtool-0.5.0
— kjana@... (YANAGAWA Kazuhisa)
1999/11/05
In message <19991105025532K.hiwada@kuee.kyoto-u.ac.jp>
[#867] call with a Proc — ts <decoux@...>
11 messages
1999/10/28
[#868] Re: call with a Proc
— gotoken@... (GOTO Kentaro)
1999/10/28
Hi,
[#877] local / dynamic variables — ts <decoux@...>
11 messages
1999/10/29
[#878] Re: local / dynamic variables
— gotoken@... (GOTO Kentaro)
1999/10/29
Hi,
[ruby-talk:00868] Re: call with a Proc
From:
gotoken@... (GOTO Kentaro)
Date:
1999-10-28 06:11:16 UTC
List:
ruby-talk #868
Hi,
In message "[ruby-talk:00867] call with a Proc"
on 99/10/28, ts <decoux@moulon.inra.fr> writes:
> I've some problem to understand how ruby pass its argument, specially when
> it has a proc has parameter.
>moulon% cat b.rb
>#!/usr/bin/ruby
>require "ftplib"
>b = FTP.new("moulon.inra.fr", "ftp", 'ts@moulon.inra.fr')
>b.list('pub').each {|i| puts i}
>b.retrlines("LIST pub", Proc.new {|i| puts i})
>b.list('pub', Proc.new {|i| puts i})
FTP#list is defined as
def list(*args, &block) ...
which means to be called in the forms as
b.list(arg1, arg2, ...){ ... }
or
b.list(arg1, arg2, &Proc.new{ ... })
This definition form is used to give a name to block. For instance,
the following travarses tree recursively and evaluate block at each
nodes:
class Tree
def Tree.[](*args)
Tree.new(*args)
end
def initialize(data, *args)
@data = data
@children = args unless args.empty?
end
def each(other = :PRE, &block)
yield @data if other == :PRE
if @children
@children.each{|node| node.each(&block)}
end
yield @data if other == :POST
end
end
t = Tree[3, Tree[2], Tree["foo"]]
t.each{|i| p i}
t.each(:POST){|i| p i}
Hope this helps
-- gotoken