Hello, Im trying to learn ruby by using koans. Now I have to fill in this part. def test_some_system_objects_always_have_the_same_id assert_equal --, false.object_id assert_equal --, true.object_id assert_equal --, nil.object_id end According to the answers I have to fill in like this : def test_some_system_objects_always_have_the_same_id assert_equal 0, false.object_id assert_equal 2, true.object_id assert_equal 4, nil.object_id end But how can I normally know the id of a object ? Roelof -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ym3Iw2DuGgcJ. For more options, visit https://groups.google.com/groups/opt_out.
Roelof Wobben wrote in post #1076512:> Hello, > > Im trying to learn ruby by using koans. > > Now I have to fill in this part. > > def test_some_system_objects_always_have_the_same_id > assert_equal --, false.object_id > assert_equal --, true.object_id > assert_equal --, nil.object_id > end > > According to the answers I have to fill in like this : > > def test_some_system_objects_always_have_the_same_id > assert_equal 0, false.object_id > assert_equal 2, true.object_id > assert_equal 4, nil.object_id > end > > But how can I normally know the id of a object ?puts false.object_id puts true.object_id puts nil.object_id -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Christopher R. Maden
2012-Sep-19 03:09 UTC
Re: Koans question : Don''t understand the answers
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 09/18/2012 01:23 PM, roelof wrote:> But how can I normally know the id of a object ?Meditate on the name of the test. ~Chris - -- Chris Maden, text nerd <URL: http://crism.maden.org/ > LIVE FREE: vote for Gary Johnson, Libertarian for President. <URL: http://garyjohnson2012.com/ > <URL: http://lp.org/ > GnuPG fingerprint: DB08 CF6C 2583 7F55 3BE9 A210 4A51 DBAC 5C5C 3D5E -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iQEcBAEBAgAGBQJQWTd7AAoJEEpR26xcXD1eKP0H+wXeq3tj6pjBFCK2qNtheIk0 w4qu/0BlwuMH5BygmY4GzrOPFNnjpRUO+MUnYXiGt36EWX4c8Fvgs+7wF59dIfMy mFibB4a4ftz/I4tPJ185UNpcQRt/t1DNMx2H8eM5FqBQmQxrcGJSLyztYSIJcFhe FVzmiO9FM86HVSZnSAzVDzFKkWWB5R/+mzzzuN3KSseoRLLXDrhnHH2CyIfXIPne d0QeD8swvE+yRAH4hh2Gl4bYooyOQE464GOgjF5dUXlN9u/hyVanBOWC2g1hPCID 5puWm/npzg1EbYVFexiL4jIi91ZOgAU0VDqZegOj4yvCGu+pxjkXohqeuF95iEE=JWUI -----END PGP SIGNATURE----- -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
As far as i know, ruby use memory location to generate object''s id, normally any dynamic objects(runtime generate objects) will have different object_id, for example "foo".object_id not equal with "foo".object_id. But, any object like number, true, false ,nil and symbol all have fixed object_id -- rubyonrailsx Sent with Sparrow (http://www.sparrowmailapp.com/?sig) On Wednesday, September 19, 2012 at 1:23 AM, roelof wrote:> Hello, > > Im trying to learn ruby by using koans. > > Now I have to fill in this part. > > def test_some_system_objects_always_have_the_same_id > assert_equal --, false.object_id > assert_equal --, true.object_id > assert_equal --, nil.object_id > end > > According to the answers I have to fill in like this : > > def test_some_system_objects_always_have_the_same_id > assert_equal 0, false.object_id > assert_equal 2, true.object_id > assert_equal 4, nil.object_id > end > > But how can I normally know the id of a object ? > > Roelof > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com (mailto:rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ym3Iw2DuGgcJ. > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Everybody thanks for the explanation. I have another problem. On this : def test_accessing_hashes_with_fetch hash = { :one => "uno" } assert_equal "uno", hash.fetch(:one) assert_raise("Class: <IndexError> Message: <"key not found"> ---Backtrace--- ./about_hashes.rb:27:in `fetch'' ./about_hashes.rb:27:in `test_accessing_hashes_with_fetch'' ") do hash.fetch(:doesnt_exist) end I get always a syntax error. How to solve this one? Roelof Op woensdag 19 september 2012 05:29:59 UTC+2 schreef cming xu het volgende:> > As far as i know, ruby use memory location to generate object''s id, > normally any dynamic objects(runtime generate objects) will have different > object_id, for example "foo".object_id not equal with "foo".object_id. But, > any object like number, true, false ,nil and symbol all have fixed object_id > > -- > rubyonrailsx > Sent with Sparrow <http://www.sparrowmailapp.com/?sig> > > On Wednesday, September 19, 2012 at 1:23 AM, roelof wrote: > > Hello, > > Im trying to learn ruby by using koans. > > Now I have to fill in this part. > > def test_some_system_objects_always_have_the_same_id > assert_equal --, false.object_id > assert_equal --, true.object_id > assert_equal --, nil.object_id > end > > According to the answers I have to fill in like this : > > def test_some_system_objects_always_have_the_same_id > assert_equal 0, false.object_id > assert_equal 2, true.object_id > assert_equal 4, nil.object_id > end > > But how can I normally know the id of a object ? > > Roelof > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonra...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<javascript:> > . > To unsubscribe from this group, send email to > rubyonrails-ta...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/ym3Iw2DuGgcJ. > For more options, visit https://groups.google.com/groups/opt_out. > > > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/k_QtwKnd7sIJ. For more options, visit https://groups.google.com/groups/opt_out.
On Sep 19, 4:29 am, rubyonrailsx <rubyonrai...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> As far as i know, ruby use memory location to generate object''s id, normally any dynamic objects(runtime generate objects) will have different object_id, for example "foo".object_id not equal with "foo".object_id. But, any object like number, true, false ,nil and symbol all have fixed object_id >Although this is an implementation detail you''d be I''ll advised to rely on - on my rubinius install for example the object id of nil is 26 Fred> -- > rubyonrailsx > Sent with Sparrow (http://www.sparrowmailapp.com/?sig) > > > > > > > > On Wednesday, September 19, 2012 at 1:23 AM, roelof wrote: > > Hello, > > > Im trying to learn ruby by using koans. > > > Now I have to fill in this part. > > > def test_some_system_objects_always_have_the_same_id > > assert_equal --, false.object_id > > assert_equal --, true.object_id > > assert_equal --, nil.object_id > > end > > > According to the answers I have to fill in like this : > > > def test_some_system_objects_always_have_the_same_id > > assert_equal 0, false.object_id > > assert_equal 2, true.object_id > > assert_equal 4, nil.object_id > > end > > > But how can I normally know the id of a object ? > > > Roelof > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > > To view this discussion on the web visithttps://groups.google.com/d/msg/rubyonrails-talk/-/ym3Iw2DuGgcJ. > > For more options, visithttps://groups.google.com/groups/opt_out.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.