# Using previous gems with latest ruby

**URL:** <https://www.ruby-forum.com/t/using-previous-gems-with-latest-ruby/208537>\
**Category:** Ruby\
**Created:** [June 20, 2011, 11:15pm UTC](https://www.ruby-forum.com/t/using-previous-gems-with-latest-ruby/208537 "2011-06-20T23:15:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [June 20, 2011, 11:15pm UTC](https://www.ruby-forum.com/t/using-previous-gems-with-latest-ruby/208537/1 "2011-06-20T23:15:13Z")

</div>

Hi,

Is it possible to use previous gems to be used with Latest Ruby 1.9.2

Actually earlier i use Ruby 1.8.7 and netssh 1.1.2 and needle 1.3.0

I upgrade to Ruby 1.9.2.

However with Ruby 1.9.2,netssh and needle gems are intergrated, plz  
correct me if im wrong, but for sure syntax are changed for netssh  
commands.

I have code which i use to send commands to remote linux machine, which  
is used to work preciously with Ruby 1.8.7 and netssh 1.1.2.

Code is like :

def issueCommandInKazBox(okMachine="", command="", matchLog="",  
user=“admin”, passwd=“kazeon”)  
puts " issueCommandInKazMachine=#{okMachine}"  
puts " issueCommandInKazcommand=#{command}"  
puts " issueCommandInKazstatus=#{matchLog}"  
puts " issueCommandInKazuser=#{user}"  
puts " issueCommandInKazpasswd=#{passwd}"

tempString = “”  
Net::SSH.start(okMachine, user, :password =\> passwd, :paranoid =\> false  
) do |session|  
#Net::SSH.start(okMachine, user, passwd) do |session|

session.open\_channel do |channel|

```
channel.on_success do
  puts "shell was started successfully!"

  puts "Adding command - #{command}..."

  channel.send_data "#{command}\n"

  channel.send_data "exit\n" # tell the shell to exit
end
channel.on_failure do
  puts "shell could not be started!"
end

channel.on_data do |ch,data|
  puts "recieved the following from shell"
  puts "#{data}"
  tempString = tempString + "\n" + data
end

channel.on_close do
  puts "shell terminated"
end

channel.send_request "shell", nil, true

```

end  
session.loop  
end

$\_ = tempString  
$outputofissueCommandInKazBox = tempString  
if /#{matchLog}/  
puts “PASSED! issueCommandInKazBox - find match log - #{matchLog}”  
return true  
else  
puts “FAILED! issueCommandInKazBox - could not find match log -  
#{matchLog}”  
return false  
end

end

But now with Ruby 1.9.2 and netssh 2.1.4. This doesn;t work.

So is it possible to install ruby 1.9.2 and then netssh 1.1.2 and then  
while executing scripts i can direct script to use netssh 1.1.2  
installed dir command so that above code works.

Currently it throws me error like :

1. Error:  
test\_0001(TC\_I18N):  
NoMethodError: undefined method `critical=' for Thread:Class C:/Ruby192/lib/ruby/site_ruby/1.9.1/needle/thread.rb:42:in`lock’  
internal:prelude:8:in `synchronize' C:/Ruby192/lib/ruby/site_ruby/1.9.1/needle/service-point.rb:117:in`instance  
’  
C:/Ruby192/lib/ruby/site\_ruby/1.9.1/needle/container.rb:308:in `get' C:/Ruby192/lib/ruby/site_ruby/1.9.1/needle/registry.rb:124:in`bootstrap’  
C:/Ruby192/lib/ruby/site\_ruby/1.9.1/needle/registry.rb:106:in  
`initialize' C:/Ruby192/lib/ruby/site_ruby/1.9.1/net/ssh/session.rb:265:in`new’  
C:/Ruby192/lib/ruby/site\_ruby/1.9.1/net/ssh/session.rb:265:in  
`process_argum ents' C:/Ruby192/lib/ruby/site_ruby/1.9.1/net/ssh/session.rb:107:in`initialize’  
C:/Ruby192/lib/ruby/site\_ruby/1.9.1/net/ssh.rb:50:in `new' C:/Ruby192/lib/ruby/site_ruby/1.9.1/net/ssh.rb:50:in`start’  
C:/IE\_AUTOMATION/kazeon/qa/watir-v1\_4-TIP/Lib/KazeonCommon/BasicMethodLibrar  
y.rb:873:in `issueCommandInKazBox' C:/IE_AUTOMATION/kazeon/qa/watir-v1_4-TIP/KazModules/I18N/I18N_Regression.rb :78:in`test\_0001’

Bhavesh

---

<div class="post-metadata">

**Author:** ![bhavesh1\_sharma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/dfb087/32.png) [@bhavesh1\_sharma](https://www.ruby-forum.com/u/bhavesh1_sharma)\
**Post date:** [June 21, 2011, 11:29am UTC](https://www.ruby-forum.com/t/using-previous-gems-with-latest-ruby/208537/2 "2011-06-21T11:29:20Z")

</div>

Bhavesh S. wrote in post #1006480:

> Is it possible to use previous gems to be used with Latest Ruby 1.9.2

Maybe. Depends on the gem. See [http://isitruby19.com/](http://isitruby19.com/)

> But now with Ruby 1.9.2 and netssh 2.1.4. This doesn;t work.  
> So is it possible to install ruby 1.9.2 and then netssh 1.1.2 and then  
> while executing scripts i can direct script to use netssh 1.1.2  
> installed dir command so that above code works.

Assuming the older gem is not 1.9.2 compatible, then no.

The better approach is to branch your code based on Ruby version  
detection. Something along the line of:

if RUBY\_VERSION.include?(“1.8”)

# call method for 1.8

elsif RUBY\_VERSION.include?(“1.9”)

# call method for 1.9

end

– gw
