menurut saya itu bukan bug..
ruby itu hampir sama dengan java.
semua variable aja di buat kalo di buat oleh 'new' atau di assign valuenya..

var = nil if false -----> var itu tidak akan pernah di isi oleh nil. karena if 
nya false
 var.nil? #=> true   ---> ini pasti akan true.. karena variable var itu belom 
di buat..
   hal ini sama kalo coba ini di irb:
       a.nil? ===> true
        a = 'test"  
       a.nil? ===> false
keterangan: a.nil? line pertama, akan true karena a belom di assign valuenya..
                      a.nil? line tiga, akan false karena a sudah di assign 
valuenya..

tambahan---> di ruby variable itu akan nil jika variable nya belom di assgin 
valuenya, atau sudah di assign valuenya dengan value nil

* tambahan pertanyaan:
   contoh:
    a = 0
    b = ""
    if a
        b = 'test'
    end

    nilai b terakhir adalah "test", KENAPA?? kan a=0 itu false

   


semoga membantu...




Arie Kusuma Atmaja <[EMAIL PROTECTED]> wrote:                             I 
tested it using Ruby 1.8.6 patch 111 and also Ruby 1.9.0 (revision 15968).
 
 var = nil if false
 var.nil? #=> true
 
 I actually saw it from tobi's blog, then I discussed with a perler who
 loves ruby as well, here's a copy paste. (Bottomline: is it a feature
 or a bug????)
 
 12:52:37 PM edpratomo: kok bisa gitu? (yg irb itu)
 12:52:49 PM Rie!: bug of the day -_-
 12:52:56 PM edpratomo: ruby 1.9?
 12:53:28 PM Rie!: 1.8.6 as well
 12:55:09 PM edpratomo: oh i understand
 12:55:31 PM edpratomo: var = nil if false creates var
 12:56:01 PM Rie!: it's just like the stupid param variable is still
 available outside of the block/yield
 12:56:07 PM edpratomo: irb(main):005:0> var = "blah" if false
 => nil
 irb(main):006:0> var
 => nil
 
 12:56:32 PM edpratomo: so it's not a bug
 12:56:58 PM edpratomo: ever got bitten by the leaky block scope?
 12:57:18 PM Rie!: how come it's not a bug :-B var should be undefined local var
 12:57:20 PM Rie!: not nil
 12:57:51 PM edpratomo: try to post that to ruby-talk :-) i believe you
 will get "it's not a bug" replies
 12:58:11 PM Rie!: that's from tobias luetjke blog
 12:58:20 PM Rie!: so i believe many rubyists had noticed that
 12:58:46 PM edpratomo: has been discussed in ruby-talk/core?
 12:58:58 PM Rie!: haven't checked yet
 1:00:02 PM edpratomo: imho it's not a bug. that foo = nil if false
 creates unitialized foo.
 1:00:31 PM edpratomo: in perl iirc such expression will be caught
 1:00:39 PM Rie!: well it shouldn't execute the command inside that if false
 1:01:04 PM edpratomo: if the if clause is evaluated first.
 1:03:56 PM edpratomo: perl -wle'my $foo = "ok" if 0; print $foo'
 Use of uninitialized value in print at -e line 1.
 
 1:04:45 PM edpratomo:  perl -Mstrict -wle'my $foo = "ok" if 0; print $foo'
 Use of uninitialized value in print at -e line 1
 1:05:03 PM edpratomo: it's a warning. not error.
 1:05:22 PM edpratomo: so $foo is created, but unitialized.
 1:05:38 PM edpratomo: in perl it will issue warning
 
 [in bahasa indonesia]
 
 Saya sebetulnya melihat ini dari blog Tobi kemudian saya berdiskusi
 bersama seorang pengguna perl yang juga mencintai ruby, berikut tadi
 copy paste nya. (Inti dari pertanyaan saya adalah apakah ini fitur
 ataukah bug di ruby????)
 
 -- 
 blog: http://tinyurl.com/2bjgvn,
 ruby: http://www.ruby-lang.org/id/about
 
 "Developer Time is expensive...
 Servers are cheap...", Ezra Zygmuntowicz - Merb
 
     
                                       

 Send instant messages to your online friends http://uk.messenger.yahoo.com 

[Non-text portions of this message have been removed]

Kirim email ke