Forum: Ruby on Rails IRB hex values

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Gerard (Guest)
on 2006-01-06 13:47
(Received via mailing list)
Hi all,

Im working on a copy contact info into project method. Nosing aroundwith
IRB I
see a hex value. Named Contact:0x40ca01cc

 #<Contact:0x40ca01cc @attributes={"name"=>"GP-net", "id"=>"7",
"lastname"=>"Petersen", "firstname"=>"Gerard"}>

Why is it there like that and not in a human readable way?


-- Method:

@project = Project.new
@project_contact = ProjectContact.new

@contacts_list = Contact.find_by_sql('select t1.name, t2.firstname,
t2.lastname, t2.id from companies AS t1, contacts AS t2 where t1.id =
t2.company_id order by t1.name')

@project_contacts = @contacts_list.collect { |c| [ c.name + " - " +
c.firstname + " " + c.lastname, c.id ] }

render_action 'edit_project'

-- Models:

class Project < ActiveRecord::Base
	has_one :project_contact
	has_many :project_products
end
class ProjectContact < ActiveRecord::Base
	belongs_to :project
end
class ProjectProduct < ActiveRecord::Base
	belongs_to :project
end
--
"Who cares if it doesn't do anything?  It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."

My $Grtz =~ Gerard;
~
:wq!
Alex Y. (Guest)
on 2006-01-06 14:20
(Received via mailing list)
Gerard wrote:
> Hi all,
>
> Im working on a copy contact info into project method. Nosing aroundwith IRB I
> see a hex value. Named Contact:0x40ca01cc
>
>  #<Contact:0x40ca01cc @attributes={"name"=>"GP-net", "id"=>"7",
> "lastname"=>"Petersen", "firstname"=>"Gerard"}>
>
> Why is it there like that and not in a human readable way?

That *is* the human readable way :-)  It's Ruby's internal ID for that
specific Contact instance, rather than anything related to the database.
  if you did another Contact.find(7), you'd get the same DB info, but
that hex number would be different.

I don't know how it's implemented internally, but I wouldn't be
surprised if it was a hash key, or an address lookup of some form.
Gerard (Guest)
on 2006-01-06 19:18
(Received via mailing list)
Alex,

Thanx. I just thought I was asking my app the wrong questions.

Regards,

Gerard.

On Friday 06 January 2006 13:20, Alex Y. tried to type something
like:
>
> That *is* the human readable way :-)  It's Ruby's internal ID for that
> specific Contact instance, rather than anything related to the database.
>   if you did another Contact.find(7), you'd get the same DB info, but
> that hex number would be different.
>
> I don't know how it's implemented internally, but I wouldn't be
> surprised if it was a hash key, or an address lookup of some form.

--
"Who cares if it doesn't do anything?  It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."

My $Grtz =~ Gerard;
~
:wq!
This topic is locked and can not be replied to.