非常簡單,但我無法找到答案。任何方式獲得紅寶石和/或陣列的標題或名稱在紅寶石
說我有在YAML傾倒這樣的對象:
page:
page_url: http://www.stackoverflow.com/
created_at: "2011-08-10T11:00:19Z"
website_id: 1
updated_at: "2011-08-10T11:00:19Z"
id: 1
Hash
我從它的哈希使用的.class和標題是頁面轉儲知道。我可以像通常那樣引用任何鍵。你究竟如何獲得散列的標題或名稱?數組是一樣的嗎? object.methods的
結果
哈希
presence
zip
find_index
invert
silence_stderr
enum_slice
deep_merge
load
gem
require_dependency
extract!
minmax
encode64
rehash
debugger
methods
send
assert_valid_keys
replace
values_at
empty?
group_by
diff
taint
instance_variable_defined?
shift
stringify_keys
take
to_param
to_yaml
key?
find_all
update
silence_stream
as_json
singleton_class
keys
require
many?
min_by
each_cons
entries
to_hash
singleton_methods
instance_eval
require_library_or_gem
to_json
first
require_or_load
nil?
b64encode
take_while
select
deep_merge!
with_options
extractable_options?
exclude?
max_by
enum_cons
deep_symbolize_keys
protected_methods
instance_exec
display
sort
store
returning
tainted?
method
delete_if
include?
stringify_keys!
untaint
instance_of?
merge!
symbolize_keys
drop
equal?
suppress
reject
merge
minmax_by
sum
to_set
yaml_initialize
hash
private_methods
all?
sort_by
default_proc
to_query
silence_warnings
`
require_association
kind_of?
freeze
acts_like?
drop_while
eql?
indexes
html_safe?
collect
id
reverse_merge
slice
reject!
grep
each_value
instance_values
with_warnings
any?
public_methods
breakpoint
symbolize_keys!
object_id
is_a?
has_key?
cycle
indices
to_options
except!
map
member?
tap
type
fetch
with_indifferent_access
each_with_index
decode64
count
each_key
instance_variable_names
enable_warnings
one?
instance_variables
try
__id__
frozen?
suppress_warnings
clear
load_dependency
to_enum
to_yaml_properties
has_value?
to_a
respond_to?
each_with_object
each
taguri
inject
slice!
class
encode_json
reverse_update
length
enum_with_index
instance_variable_get
each_pair
copy_instance_variables_from
none?
taguri=
find
==
__send__
===
enum_for
min
to_options!
extend
value?
to_s
default
index_by
index
size
reduce
blank?
unloadable
to_yaml_style
default=
clone
reverse_each
decode_b
=~
instance_variable_set
detect
values
to_xml
max
each_slice
inspect
[]
class_eval
present?
duplicable?
reverse_merge!
except
partition
delete
[]=
dup
鍵和鍵不能因爲某些原因被引用。觀察
puts object.keys
回報
undefined method `keys' for nil:NilClass
puts object.key
回報
undefined method `key' for #<Hash:0x103aeb0b0>
解決方法:你們是要去^ h吃了這個。我通過運行修復了問題
sudo gem update
沒有笑話。它更新了紅寶石1.8.7到1.8.7,就是這樣。問題解決了。我從來沒有對我的ruby安裝做過任何瘋狂的事情,但看起來它裏面的東西肯定與散列有關。或者這可能是一個非常罕見的錯誤。我無法找到更新跟蹤中會導致此問題的任何內容。感謝所有幫助過我的人。
並且你不知道它。關鍵就在那裏 – OVERTONE
我想你要找的內容已經在這裏找到答案:紅寶石 - 獲取變量的名稱] [1] [1]:HTTP://計算器。COM /問題/ 58482 /紅寶石獲得-一個變量名 – 2011-08-10 18:01:43
我認爲你在尋找什麼,已經在這裏找到答案:紅寶石 - 獲取變量的名稱] [1] [1]: http://stackoverflow.com/questions/58482/ruby-get-a-variables-name – 2011-08-10 18:02:52