ruby-2.0

Ruby request to https - “in `read_nonblock': Connection reset by peer (Errno::ECONNRESET)”

不羁岁月 提交于 2019-12-09 04:20:23
问题 Here is my code domain = 'http://www.google.com' url = URI.parse "https://graph.facebook.com/fql?q=SELECT%20url,normalized_url%20FROM%20link_stat%20WHERE%20url='#{domain}'" req = Net::HTTP::Get.new url.path res = Net::HTTP.start(url.host, url.port) {|http| http.request req} puts res.body and it gives me /home/alex/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:153:in `read_nonblock': Connection reset by peer (Errno::ECONNRESET) from /home/alex/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0

How to get the name of the calling alias method?

邮差的信 提交于 2019-12-07 05:29:54
问题 I am having method called link_to_admin then I have aliased another method called simple_link_to def link_to_admin(name,url,options={}) # My stuff here link_to(name,url,options) end alias_method :simple_link_to, :link_to_admin Here I am facing one problem if I call link_to_admin , I want print the value into <li> tag Ex. def link_to_admin(name,url,options={}) # My stuff here menu = "" menu << "<li> #{link_to(name,url,options)}</li>" menu.html_safe end And if I call simple_link_to no need of

problems installing nokogiri gem on mac osx snow leopard with Ruby 2.0.0-p353

ぃ、小莉子 提交于 2019-12-07 05:02:25
问题 I have tried installing nokogiri on my rvm ruby 2.0.0-p353 using both homebrew and macports following instructions on the nokogiri installation page found here: http://nokogiri.org/tutorials/installing_nokogiri.html In both, I get exactly the same error message of bad file descriptor as shown below: → sudo gem install nokogiri Fetching: mini_portile-0.5.2.gem (100%) Successfully installed mini_portile-0.5.2 Fetching: nokogiri-1.6.1.gem (100%) Building native extensions. This could take a

Cannot load files using require

喜欢而已 提交于 2019-12-06 08:03:09
I just downloaded Ruby 2.0 and have a serious problem with require when I try to run a simple Sinatra app: /Users/Kuba/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- sinatra (LoadError) from /Users/Kuba/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require' from test.rb:1:in `<main>' Also, this and other programs I have a problem with now, worked perfectly fine when i was using Ruby 1.8.7. What should I do? Daniël W. Crompton I had this problem today too when

Access STDIN of child process without capturing STDOUT or STDERR

孤者浪人 提交于 2019-12-06 07:39:09
问题 In Ruby, is it possible to prevent the standard input of a spawned child process from being attached to the terminal without having to capture the STDOUT or STDERR of that same process? Backticks and x-strings ( `...` , %x{...} ) don't work because they capture STDIN. Kernel#system doesn't work because it leaves STDIN attached to the terminal (which intercepts signals like ^C and prevents them from reaching my program, which is what I'm trying to avoid). Open3 doesn't work because its methods

Why does `send` fail with Ruby 2.0 refinement?

为君一笑 提交于 2019-12-05 18:41:56
问题 Why does this not work? module StringRefinement refine String do def bar length end end end using StringRefinement "abcdefghijklmnopqrstuvwxyz".send(:bar) #NoMethodError: undefined method 'bar' for "abcdefghijklmnopqrstuvwxyz":String Can someone explain why send doesn't work here? And is there a way to dynamically call methods defined in a refinement? I can't seem to find a good, full explanation of how refinements work in Ruby 2.0. 回答1: Because the specification says so: Indirect method

Cannot run Unicorn with Ruby 2.0

旧城冷巷雨未停 提交于 2019-12-05 13:13:06
On my ubuntu machine, I can run unicorn on ruby 1.9.3, however, it does not seem to work with ruby 2.0. Any idea why? root@dev:/home/karan# rvm use 1.9 Using /usr/local/rvm/gems/ruby-1.9.3-p429 root@dev:/home/karan# unicorn -v unicorn v4.6.3 root@dev:/home/karan# rvm use 2.0 Using /usr/local/rvm/gems/ruby-2.0.0-p195 root@dev:/home/karan# unicorn -v /usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- unicorn/launcher (LoadError) from /usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems

Trim a trailing .0

て烟熏妆下的殇ゞ 提交于 2019-12-05 12:03:27
问题 I have an Excel column containing part numbers. Here is a sample As you can see, it can be many different datatypes: Float , Int , and String . I am using roo gem to read the file. The problem is that roo interprets integer cells as Float , adding a trailing zero to them (16431 => 16431.0). I want to trim this trailing zero. I cannot use to_i because it will trim all the trailing numbers of the cells that require a decimal in them (the first row in the above example) and will cut everything

How to get the name of the calling alias method?

风流意气都作罢 提交于 2019-12-05 10:34:56
I am having method called link_to_admin then I have aliased another method called simple_link_to def link_to_admin(name,url,options={}) # My stuff here link_to(name,url,options) end alias_method :simple_link_to, :link_to_admin Here I am facing one problem if I call link_to_admin , I want print the value into <li> tag Ex. def link_to_admin(name,url,options={}) # My stuff here menu = "" menu << "<li> #{link_to(name,url,options)}</li>" menu.html_safe end And if I call simple_link_to no need of <li> tag. So currently I am passing one options like li_required then am checking condition in my method

Google plus insert activity on stream

孤街浪徒 提交于 2019-12-05 02:47:08
问题 Tough time inserting an activity to google plus stream. After referring google developers guide. I found an example for java - https://developers.google.com/+/domains/posts/creating Is there a similar example to execute the activites.insert query using google-api-ruby-client. I followed following steps: Define access to app via omniauth-google-oauth2 GOOGLE_CONSUMER_KEY = google_config['KEY'] GOOGLE_CONSUMER_SECRET = google_config['SECRET'] google_scope = "userinfo.email, userinfo.profile,