ruby语言语法(如何使用platform_info变量

时间:2010-06-09 10:04:02

标签: ruby syntax

 class EncodeDemoTest < Test                      #inheritance in ruby  
      def setup(platform_info, logdir)
        @telnet_ip                  = platform_info["telnet_ip"]
        @telnet_login               = platform_info["telnet_login"]
        @telnet_password            = nil
        @filesys_path               = platform_info["filesys_path"]
        @host_files_path            = platform_info["host_files_path"]
        @host_machine_ip            = platform_info["host_machine_ip"]
        @linuxserver_ip             = platform_info["linuxserver_ip"]
        @target_prompt              = platform_info["target_prompt"]
        @demo_execuable_path        = platform_info["demo_execuable_path"]
        @mts4ea_machine_ip          = platform_info["mts4ea_machine_ip"]
        @mts4ea_files_path          = platform_info["mts4ea_files_path"]
        @ffmpeg_machine_ip          = platform_info["ffmpeg_machine_ip"]
        @ffmpeg_service_machine_ip  = platform_info["ffmpeg_service_machine_ip"]          
        @ffmpeg_files_path          = platform_info["ffmpeg_files_path"]
        @ffmpeg_login               = platform_info["ffmpeg_login"]
        @ffmpeg_password            = platform_info["ffmpeg_password"]
        @ffmpeg_prompt              = platform_info["ffmpeg_prompt"]
        @platform_info              = platform_info

任何人都可以告诉我如何在setup方法中传递参数。意味着该语法意味着什么platform_info["telnet_ip"]

1 个答案:

答案 0 :(得分:0)

platform_info似乎是Hash

setup将使用setup({'telnet_ip' => 'value'}, 'logdir_value')platform_info["telnet_ip"]之类的内容进行调用,然后会从platform_info为键"telnet_ip"返回值。

<强>更新

鉴于代码:

@board = Target::TelnetClient.new "192.168.247.68", "root", 
  @telnet_password, logdir + "/log.txt"
app = Target::EncodeDemoApp.new() app.setup(@board, @demo_execuable_path)

看起来@board不是Hash,而是Target::TelnetClient,必须使用[]方法才能使其行为像Hash。< / p>

如果您想了解某些课程,可以使用class方法,例如你可以加入你的程序:

puts "@board is a #{@board.class}"
puts "@demo_executable_path is a #{@demo_executable_path.class}"

对于@board,要查看它包含的值(telnet_ip,telnet_login等),您可以尝试:

puts @board.keys.inspect

最后,要查看对象提供的方法,可以使用public_methods例如

puts @board.public_methods.inspect