ruby-1.9.3

Capturing warning messages

非 Y 不嫁゛ 提交于 2019-12-23 04:14:13
问题 Is there a way to capture the warnings, something like rescue for exceptions? I do not want to simply disable the warnings (by doing $VERBOSE = nil ) but want to capture the content of the warning messages during run time. 回答1: You can redirect stderr to a StringIO object to capture the warnings output in a string: require 'stringio' old_stderr = $stderr $stderr = StringIO.new Foo = 1 Foo = 2 # generates a warning puts $stderr.string # prints the warning $stderr = old_stderr 回答2: require

Capturing warning messages

让人想犯罪 __ 提交于 2019-12-23 04:14:07
问题 Is there a way to capture the warnings, something like rescue for exceptions? I do not want to simply disable the warnings (by doing $VERBOSE = nil ) but want to capture the content of the warning messages during run time. 回答1: You can redirect stderr to a StringIO object to capture the warnings output in a string: require 'stringio' old_stderr = $stderr $stderr = StringIO.new Foo = 1 Foo = 2 # generates a warning puts $stderr.string # prints the warning $stderr = old_stderr 回答2: require

uninitialized constant SOCKSSocket

匆匆过客 提交于 2019-12-23 03:34:19
问题 I am running ruby 1.9.3 on a linux box. I would like to use SOCKSSocket, however, I continue to run into the following error: uninitialized constant SOCKSSocket simple test using IRB irb(main):001:0> require 'resolv-replace' => true irb(main):002:0> SOCKSSocket NameError: uninitialized constant SOCKSSocket from (irb):2 from /usr/local/bin/irb:12:in `<main>' here is the source code directly from resolv-replace.rb class SOCKSSocket < TCPSocket # :stopdoc: alias original_resolv_initialize

Bundler could not find compatible versions for gem, updating Rails app

我的未来我决定 提交于 2019-12-20 12:28:13
问题 After createing a brand new rails app Following the official rails blog post, attempting to convert apps to rails 3.2.0.rc2 yields the following Updated Gemfile to depend on rails ~> 3.2.0.rc2 gem 'rails', '~>3.2.0.rc2' Updated Gemfile to depend on sass-rails ~> 3.2.3 gem 'sass-rails', '~> 3.2.3' $ bundle install Fetching source index for http://rubygems.org/ Bundler could not find compatible versions for gem "activesupport": In snapshot (Gemfile.lock): activesupport (3.1.1) In Gemfile: rails

How does pack() and unpack() work in Ruby

旧巷老猫 提交于 2019-12-18 12:38:57
问题 In Ruby why we need array Packing ? How does directive help to do such packing? I ran some code in my console to see what and how directives looks like in Array packing.But the output is closely same with each directives. Then in core how they differs? irb(main):003:0> n = [ 65, 66, 67 ] => [65, 66, 67] irb(main):004:0> n.pack("ccc") => "ABC" irb(main):005:0> n.pack("C") => "A" irb(main):006:0> n.pack("CCC") => "ABC" irb(main):007:0> n.pack("qqq") => "A\x00\x00\x00\x00\x00\x00\x00B\x00\x00

install ruby 1.9.3 using rvm on ubuntu [duplicate]

天大地大妈咪最大 提交于 2019-12-18 10:51:40
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Ruby 1.9.2 and Rails 3 cannot open rails console I have already installed rvm and ruby 1.9.2, both working properly. Using rvm version 1.10.2. I previously installed the rvm packages readline/zlib, but now I'm having big troubles with readline now. I'm trying to install ruby 1.9.3 in rvm, but I always end up having readline not found. I tried to follow different solutions: rvm remove 1.9.3 rvm pkg install

Use default ruby version in Sublime Text 2

杀马特。学长 韩版系。学妹 提交于 2019-12-18 06:58:00
问题 My default and current version of ruby is 1.9.3. It's actually the only version that appears when I run rvm list so I don't see how I can be messing that part up. I did follow this tutorial that I found here, but it just seemed to break everything. I keep getting "No such file or directory" for all the variations of the fix I see, even the in the comments. I am on a Mac, please let me know what other information I need to post here to help you figure out how I'm breaking things. 回答1: You can

Set UTF-8 as default for Ruby 1.9.3

你离开我真会死。 提交于 2019-12-17 18:38:19
问题 I'm on Rails 4 and Ruby 1.9.3 I use "strange" characters very often, so I have to declare UTF-8 encoding at the top of all .rb files. Is there any way to set UTF-8 as the default encoding for Ruby 1.9.3? I tried all answers, but when running rake db:seed and creating an object whose attributes contain non US-ASCII valid characters, I still receive this error: `block in trace_on': invalid byte sequence in US-ASCII (ArgumentError) 回答1: To change the source encoding (i.e. the encoding your

How to cleanly initialize attributes in Ruby with new?

☆樱花仙子☆ 提交于 2019-12-17 16:27:32
问题 class Foo attr_accessor :name, :age, :email, :gender, :height def initalize params @name = params[:name] @age = params[:age] @email = params[:email] . . . end This seems like a silly way of doing it. What is a better/more idiomatic way of initalizing objects in Ruby? Ruby 1.9.3 回答1: def initialize(params) params.each do |key, value| instance_variable_set("@#{key}", value) end end 回答2: You can just iterate over the keys and invoke the setters. I prefer this, because it will catch if you pass

Rails 3.1 and Ruby 1.9.3p125: ruby-debug19 still crashes with “Symbol not found: _ruby_threadptr_data_type” [duplicate]

佐手、 提交于 2019-12-17 07:37:42
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: ruby-debug with Ruby 1.9.3? I had heard rumors that ruby 1.9.3p125 has a solution for the ruby-debug19 problem, so per instructions on the RVM site, I reinstalled 1.9.3: $ rvm reinstall 1.9.3 --patch debug --force-autoconf $ ruby -v ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.2.0] Then: gem install ruby-debug19 Added this entry to my Gemfile: gem 'ruby-debug19' Then: $ rails server -u => Booting