ruby-1.9.3

Setting an HTTP Timeout in Ruby 1.9.3

只谈情不闲聊 提交于 2019-12-07 15:30:55
问题 I'm using Ruby 1.9.3 and need to GET a URL. I have this working with Net::HTTP , however, if the site is down, Net::HTTP ends up hanging. While searching the internet, I've seen many people faced similar problems, all with hacky solutions. However, many of those posts are quite old. Requirements: I'd prefer using Net::HTTP to installing a new gem. I need both the Body and the Response Code. (e.g. 200) I do not want to require open-uri , since that makes global changes and raises some security

How the @,x,X directives work with Ruby pack()/unpack() method?

本秂侑毒 提交于 2019-12-07 12:48:06
问题 I just went through the Ruby Doc. But there is no sufficient code to understand how the below three are used in Real life programming: @ , X , x . can anyone explain it with a simple snippet? Thanks 回答1: I will give you few example and will be learning together with you: [1,2,3,4].pack("CCCC") => "\x01\x02\x03\x04" So serializes in unsigned chars. Every letter in new byte. [1,2,3,4].pack("CCXCC") => "\x01\x03\x04" [1,2,3,4].pack("CCXXC") => "\x03" Think of the 'X' as backspace directive [1,2

ERROR — : reaped #<Process::Status: pid 4335 exit 1> worker=0

若如初见. 提交于 2019-12-07 11:27:27
I am trying since 2 days to deploy on my vps (Ubuntu 12.04 Server (64 bits)) using : ruby (1.9.3-rc1), rails, capistrano, nginx and unicorn. I also follow railscast tutorial from Ryan Bates showing how to deploy on VPS from scratch. Actualy the cap deploy:cold command seems to work fine (as all the others) but when i try to go on my url i fall on "We're sorry but something went wront" => The default error page from Rails. In my production logs i get : Migrating to CreateQuestionAnswers (20130317152603) Migrating to CreateRegions (20130502212531) Migrating to AddRegionIdToSection

Ruby 1.9.3-p0 and RSpec causes frequent segmentation faults

余生颓废 提交于 2019-12-07 03:28:51
问题 Is it just me, or has Ruby 1.9.3 introduced frequent segmentation faults when running RSpec? Since upgrading to 1.9.3, I find startup time is noticeably quicker, however I get segmentation faults when running RSpec around 50% of the time. The output that I am getting from Ruby is at http://pastebin.com/89YmpzaJ and my Gemfile is at http://pastebin.com/L6r73Max Does anyone know what could be causing this? I am seeing this problem on both my CI server and my local development machine. 回答1:

Problems installing Ruby 1.9.3 with Rvm

こ雲淡風輕ζ 提交于 2019-12-06 15:57:48
问题 I am trying to install ruby 1.9.3 using this guide: http://www.moncefbelyamani.com/how-to-install-xcode-homebrew-git-rvm-ruby-on-mac/. When I run rvm install 1.9.3 I get this error Searching for binary rubies, this might take some time. No binary rubies available for: osx/10.8/x86_64/ruby-1.9.3-p392. Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies. Installing requirements for osx, might require sudo password. Skipping `brew update` make sure your

Confusion with Ruby File class related PATH methods [closed]

江枫思渺然 提交于 2019-12-06 13:05:38
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I am getting confused with the utility of the File Class methods as below: 1. File::absolute_path 2. File::realdirpath 3. File::realpath 4. File::expand_path What I tried below: irb(main):001:0> Dir.pwd => "C:/Users/Matt" irb(main):002:0

Ensure orphaned processes are killed when the parent process dies

橙三吉。 提交于 2019-12-06 12:05:34
问题 In Ruby, how do I ensure that child processes spawned from my program don't keep running when my main process exits or is killed? Initially I thought I could just use at_exit in the main process, but that won't work if my main process gets kill -9 ed or calls Kernel.exec . I need a solution that is (basically) foolproof, and cross-platform. 回答1: If you have to handle kill -9 termination for your parent app, then you have only a couple of choices that I can see: Create a work queue manager and

Does requiring a gem load everything, including things I don't use?

不打扰是莪最后的温柔 提交于 2019-12-06 09:52:34
Assume x is a gem, that contains both Hello and Goodbye classes. If I write a program that require 'x' , but only uses the Hello class. Is the Goodbye class loaded as well? knut You include scripts or files, not gems. With require 'x' you load the file x.rb . Which x.rb you load is defined by the search path, the search pathes can be modified by gem definitions (what you didn't use in your example code). Everything inside the file x.rb is loaded. If x.rb contains other require commands, those files are also loaded. 来源: https://stackoverflow.com/questions/10001106/does-requiring-a-gem-load

Named parameters in Ruby don't work? [duplicate]

心不动则不痛 提交于 2019-12-06 05:33:18
This question already has answers here : No named parameters in Ruby? (4 answers) Closed 5 years ago . I wonder why named parameters don't work as I expect. def my_method(var1, var2 = 1, var3 = 10) puts var1, var2, var3 end my_method(999, var3 = 123) The output 999 123 10 instead of (at least, as I guess should be): 999 1 123 So, what should I do to use named parameters? P.S. When I use the hash, it's not what I'm looking for yet: def my_method(var1, vars = {var2: 1, var3: 10} ) puts var1, vars[:var2], vars[:var3] end my_method(999, var3: 123) 999 123 my_method(999, var2: 111, var3: 123) 999

Matching position in gsub or scan

走远了吗. 提交于 2019-12-06 03:55:44
What is the best way to achieve the matching position (the index that would be returned by =~ ) for each match when using gsub or scan ? "hello".gsub(/./) { Regexp.last_match.offset(0).first } => "01234" See Regexp.last_match and MatchData . I came to this problem from a different direction, and could not come up with a decent solution (that is, understandable, maintainable) to do this with either gsub or scan (both built-in methods of String class). So I asked "Why do it this way?..." and looked for more natural alternatives (thanks to Nash for pointing the general direction!): #!/usr/bin/env