如何访问 ruby 中 whois 解析器返回的属性?

how to access properties returned by whois parser in ruby?

require 'rubygems'
require 'whois'

c = Whois::Client.new
r = c.lookup("seogroup.com")

puts r.admin_contacts

produces this:

#<struct Whois::Record::Contact id=nil, type=2, name="Marvin Russell", organization="SEO Group, LLC", address="222 W Ontario", city="Chicago", zip="60654", state="Illinois", country="United States", country_code=nil, phone="847-452-9902", fax=nil, email="marvin@seogroup.com", url=nil, created_on=nil, updated_on=nil>

如何获取 "state"、"email" 和 "name" 等这些属性

当我 运行 你的代码时,我得到一个数组:

2.1.2 :013 > r.admin_contacts
 => [#<struct Whois::Record::Contact id=nil, type=2, name="Marvin Russell", organization="SEO Group, LLC", address="222 W Ontario", city="Chicago", zip="60654", state="Illinois", country="United States", country_code=nil, phone="847-452-9902", fax=nil, email="marvin@seogroup.com", url=nil, created_on=nil, updated_on=nil>]

然后稍微反省一下我看到:

2.1.2 :014 > r.admin_contacts.class
 => Array 
2.1.2 :015 > r.admin_contacts.length
 => 1 
2.1.2 :016 > r.admin_contacts[0].class
 => Whois::Record::Contact 

然后我查看了可用的方法:

2.1.2 :017 > r.admin_contacts[0].methods
 => [:id, :id=, :type, :type=, :name...

然后调出姓名和电子邮件:

2.1.2 :018 > r.admin_contacts[0][:name]
 => "Marvin Russell" 
2.1.2 :019 > r.admin_contacts[0][:email]
 => "marvin@seogroup.com"