tags:

views:

57

answers:

1
 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

could anyone tell me how argument passed in setup method .means what does that syntax means platform_info["telnet_ip"]

A: 

It looks like platform_info is intended to be a Hash.

setup would be called with something like setup({'telnet_ip' => 'value'}, 'logdir_value') and platform_info["telnet_ip"] would then return the value from platform_info for the key "telnet_ip".

Update

Given the code:

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

it looks like @board is not a Hash but is a Target::TelnetClient which must have a [] method that makes it behave like a Hash.

If you want to find out what class something is you can use the class method e.g. you can put in your program:

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

For @board, to see what values it contains (telnet_ip, telnet_login etc) you could try:

puts @board.keys.inspect

Finally, to see the methods that an object provides you can use public_methods e.g.

puts @board.public_methods.inspect
mikej
thanks mikej,but could u plz expain it more like how i confirm platform_info is hash and is there any other way to call setup function other than what u wrote plzzz i m waiting gor ur respone
amit singh tomar
thanks mikej,but could u plz expain it more like how i confirm platform_info is hash and is there any other way to call setup function other than what u wrote plzzz i m waiting gor ur respone
amit singh tomar
nd i adding one line @board = Target::TelnetClient.new "192.168.247.68", "root", @telnet_password, logdir + "/log.txt" setup(@board,@demoexecuatable path)now cud u plz explain more
amit singh tomar
Please can you add some more details about what else you would like to know. I'm not sure what to add. Why would you like to call the function in a different way? What is that extra line for that you want to add?
mikej
i understood what u said platform_info is definately HASH but setup function is called like that app = Target::EncodeDemoApp.new() app.setup(@board, @demo_execuable_path)one line before this is @board = Target::TelnetClient.new "192.168.247.68", "root", @telnet_password, logdir + "/log.txt"one thing that i want to know is what value is there inside instance variable @board and how to determine @board value i tried with puts #{@board} but nt wrking and one more thins islogdir is also hesh ?? excuse if there is sumthing wrong because i new to ruby
amit singh tomar
mikej i tried with keys method but its not working cud u plzzz tell someelse methods???
amit singh tomar
Can you do `puts @board.class` and let me know what that prints.
mikej
Also, what is the output from `puts @board.public_methods.inspect`?
mikej
yaa @board.public_methods.inspect and @board.class are working fine [email protected] gives me TelnetClient class name but when i tried @board.keys.inspect i have trouble like undefined method `keys'
amit singh tomar
Can you find the code for the `TelnetClient` class? I don't think that is a standard part of Ruby so it is either specific to your project or a third party library.
mikej
mikej i m facing a problem like as i asked before @board = Target::TelnetClient.new "192.168.247.68", "root", @telnet_password, logdir + "/log.txt" is @board is a hash or what ??and u replied like it is a hash and to me it seems a hash but when i used standard ruby operator like @board.kind_of? Hash i got false as an outputso this measns it's not hash nd this code for telnetclient
amit singh tomar
module Target class TelnetClient < Client def initialize(ip, login, password, log_path = nil) super(log_path) connect(ip, login, password) end def connect(ip, login, password) @target = Net::Telnet::new( "Host" => ip) if(password == nil) @target.login(login.to_s, nil){ |c| print c} else @target.login(login.to_s, password){ |c| print c } end super() end endend
amit singh tomar
From the code you've posted it is not a `Hash`. `TelnetClient < Client` says that `TelnetClient` extends `Client` so some of the methods like the ability to say `platform_info["telnet_ip"]` must come from the `Client` class but there is no `keys` method.
mikej
hii mikeji wouls like to know is there any way to map a mdb(database) file to hash .
amit singh tomar
Mapping an mdb to a hash should be posted as a new question.
mikej