ruby-1.8

Spawning an independent thread or process in Ruby

你离开我真会死。 提交于 2020-01-12 07:23:06
问题 I may be approaching this in the wrong direction, so any help would be appreciated. I have a Ruby script which, amongst other things, starts up an executable. I want to start this executable - currently being triggered using system "" - and then continue on with the script. When the script finishes, I want it to exit but leave the executable running. Originally I had the following # Do some work # Start the executable system("executable_to_run.exe") # Continue working But executable_to_run

How do I use Ruby's SOAP::Attachment class?

一世执手 提交于 2020-01-04 14:31:25
问题 So I'm writing a Ruby client for a SOAP web service, and I've figured out how to call a simple method: # WebServiceClient.rb require 'soap/wsdlDriver' wsdl_url = 'http://urlmadness?wsdl' service = SOAP::WSDLDriverFactory.new(wsdl_url).create_rpc_driver result = service.simpleMethod(:sayHello => 'Hello') p result.return Now I need to write something that will call a web method that is expecting an attached file as a SOAP MIME Attachment (SwA). I've looked into Ruby's SOAP::Attachment class but

How to count duplicates hash itens in Ruby 1.8.5 ( Sketchup Ruby API )

喜你入骨 提交于 2019-12-30 13:37:31
问题 I need to count the duplicates, they need to be 100% identical to increase my count, but I can not use a nothing out of Ruby 1.8.5, this code will run inside a plugin in google sketchup Google Sketchup Ruby API puts VERSION 1.8.5 puts RUBY_PLATFORM i686-darwin8.10.1 product = 'Glass' x = width y = length z = density product_list = [ { "product" => 1, "x" => 200, "y" => 100, "z" => 18}, { "product" => 1, "x" => 200, "y" => 100, "z" => 18}, { "product" => 1, "x" => 300, "y" => 100, "z" => 18},

Ruby 1.8 and UTF-8 string case statement compare

こ雲淡風輕ζ 提交于 2019-12-24 11:03:43
问题 I have a Rake task (in lib/tasks directory) that I run with cron on my shared web hosting. The problem is that I want to compare a UTF-8 string using case statment but my source code is not UTF-8 encoded. If I save source code as UTF-8 there is error when I try to start it :( What I have to do? May be read this strings from external UTF-8 txt file? P.S. I'm using Ruby 1.8 P.S. I mean compare this way: result = case utf8string when 'АБВ': 1 when 'ГДИ': 2 when 'ЙКЛ': 3 when 'МНО': 4 else 5 end

Preventing timeout when connecting to a URL

穿精又带淫゛_ 提交于 2019-12-23 18:53:37
问题 I want to see the time taken to access a url using Benchmark in the code below. I also tried to do the same thing without benchmark. That is, get time at start of test and end of test, subtract the two to get the time. Both methods end in the same timeout error. require 'open-uri' require 'benchmark' response = nil puts "opening website with benchmark..." puts Benchmark.measure{ response = open('http://mywebsite.com') } puts "Done !" status = response.status puts status Error: opening website

Ruby Array#puts not using overridden implementation?

拟墨画扇 提交于 2019-12-11 23:02:27
问题 I am using Ruby 1.8.6 for the following code: # Create an array and override the #to_s on that object thing = [1,2,3] def thing.to_s 'one' end print "Using print: " print thing puts puts "Using puts: " puts thing Output: Using print: one Using puts: 1 2 3 So thing is an Array and I have overridden thing #to_s. print seems to use my overriden implementation while puts does not. Why? I have followed the source code of Kernel#puts and Kernel#print (which are C-implementations) and see that they

Does Ruby 1.8.7 head support 1.9-style hash literals?

北城以北 提交于 2019-12-11 12:19:58
问题 According to http://redmine.ruby-lang.org/issues/1183 , Ruby 1.9's {foo: 42} apparently was back-ported to Ruby 1.8. But I tried running ruby-1.8.7-head using RVM, and I got the standard syntax error: Andrew-Grimms-MacBook-Pro:ruby agrimm$ rvm use ruby-1.8.7-head Using /Users/agrimm/.rvm/gems/ruby-1.8.7-head Andrew-Grimms-MacBook-Pro:ruby agrimm$ irb ruby-1.8.7-head :001 > {a: "foo"} SyntaxError: compile error (irb):1: odd number list for Hash {a: "foo"} ^ (irb):1: syntax error, unexpected ':

Ruby - How to invert a Hash with an array values?

天大地大妈咪最大 提交于 2019-12-11 10:42:19
问题 Looking for an answer that works on Ruby 1.8.7 : For example lets say I have a hash like this: {"Book Y"=>["author B", "author C"], "Book X"=>["author A", "author B", "author C"]} and I want to get this: { "author A" => ["Book X"], "author B" => ["Book Y", "Book X"], "author C" => ["Book Y", "Book X"] } I wrote a really long method for it, but with large datasets, it is super slow. Any elegant solutions? 回答1: h = {"Book Y"=>["author B", "author C"], "Book X"=>["author A", "author B", "author

Getting error “Cannot allocate memory” for Rails

痴心易碎 提交于 2019-12-10 18:44:33
问题 In my project there is one script that returns the list of products which I have to display in a table. To store the input of the script I used IO.popen : @device_list = [] IO.popen("device list").each do |device| @device_list << device end device list is the command that will give me the product list. I return the @device_list array to my view for displaying by iterating it. When I run it I got an error: Errno::ENOMEM (Cannot allocate memory): for IO.popen I have on another script device

DBI Row / delegate behavior between ruby 1.8.7 and 2.1

╄→гoц情女王★ 提交于 2019-12-04 14:22:47
I execute the following code in ruby 1.8.7 to read rows from my database: require 'dbi' db_conn_handle = DBI.connect("DBI:Mysql:host=localhost;database=mydb;port=3306", "root") sth = db_conn_handle.prepare("select accounts.id, accounts.name from accounts;") sth.execute info = sth.to_a puts "Info: #{info[0].class}" info.each do |x, y| puts "#{x} ... #{y}" end From the output it is clear that info[0].class is DBI::Row. This code works perfectly when executed with ruby 1.8.7 (rails 3.2.17) When I try executing it in ruby 2.1.5 / rails 3.2.17, it gives the following error: /home/rjain/.rvm/rubies