我正在學習Ruby & Perl有這個非常方便的模塊,稱爲Data :: Dumper,它允許您遞歸地分析數據結構(如哈希)&允許您打印它。這在調試時非常有用。 Ruby有沒有類似的東西?Ruby的等價Perl數據:: Dumper
16
A
回答
18
查找到第
例如:
require 'pp'
x = { :a => [1,2,3, {:foo => bar}]}
pp x
也有檢測方法也工作得很好
x = { :a => [1,2,3, {:foo => bar}]}
puts x.inspect
2
3
我通常使用YAM L轉儲,如果我需要快速檢查一些東西。
在irb
的語法是簡單的y obj_to_inspect
。在一個普通的Ruby應用程序中,您可能需要向該文件添加一個require 'YAML'
,不確定。
這裏是irb
一個例子:
>> my_hash = {:array => [0,2,5,6], :sub_hash => {:a => 1, :b => 2}, :visible => true}
=> {:sub_hash=>{:b=>2, :a=>1}, :visible=>true, :array=>[0, 2, 5, 6]}
>> y my_hash # <----- THE IMPORTANT LINE
---
:sub_hash:
:b: 2
:a: 1
:visible: true
:array:
- 0
- 2
- 5
- 6
=> nil
>>
最後=> nil
只是意味着該方法不返回任何東西。它與你的數據結構無關。
相關問題
- 1. Perl hash Data :: Dumper
- 2. 在Perl中Ruby的irb等價物?
- 3. 在Data :: Dumper中是否有與Perls的Dumper()方法等價的C?
- 4. Perl eval Data :: Dumper不一致
- 5. Perl的等價PHP的compact()?
- 6. 使用Data :: Dumper的Perl持久數據存儲
- 7. 是否有與Perl的Data :: Rmap等價的Ruby?
- 8. Ruby的等價於PHP的ucfirst()函數
- 9. Ruby的等價PHP的mcrypt_encrypt()函數
- 10. Ruby的等價於PHP的「get_defined_vars」函數?
- 11. Ruby的cURL的等價物?
- 12. Ruby的等價的Python setattr()
- 13. Ruby的等價ASP.NET的Application_Start?
- 14. 如何將Data :: Dumper輸出轉換回Perl數據結構?
- 15. 這個「現代Perl」數據:Dumper示例是否可以修復?
- 16. Python等價於Ruby的包函數
- 17. 來自Perl Dumper的意外輸出
- 18. Ruby的等價PHP openssl_seal
- 19. Ruby的等價LINQ ToList()
- 20. Java的Ruby等價物ObjectSpace.each_object
- 21. python等價於ruby的__method__?
- 22. C#等價的Ruby符號
- 23. Ruby等價於Python的DictWriter?
- 24. Ruby中subprocess.Popen()的等價物?
- 25. python等價於ruby的`map.with_index`?
- 26. python等價於ruby的StringScanner?
- 27. Perl「import os」Python等價物?
- 28. Perl語句等價於C
- 29. PHP等價於Perl行嗎?
- 30. Ruby ::等價於Tie :: FIle?
順便說一句,謝謝所有這些模塊。這是我可以使用的非常好的信息。 – John 2010-01-29 18:54:46