ruby-2.0

Is there a pry debug setup that works with ruby 2.0?

∥☆過路亽.° 提交于 2019-11-30 16:38:17
问题 I'm using ruby 2.0.0-p195 on OSX. pry-debugger does not work (step/continue/next all appear to work like continue ). Is there a pry debugging gem that works with ruby 2.0? update: pry-debugger and pry-byebug both appear to work with with ruby 2.0.0-p195 in a simple project. I have some other conflict that is causing both to fail when using binding.pry in tests... update: pry-byebug is working for me with the latest ruby 2.0 release, 2.0.0-p247, with pry-byebug 1.1.1 & byebug 1.5.0 回答1: pry

What is the difference between 'include' and 'prepend' in Ruby?

半腔热情 提交于 2019-11-30 11:19:45
From the Module Module#append_features(mod) → mod => When this module is included in another, Ruby calls append_features in this module, passing it the receiving module in mod. Ruby’s default implementation is to add the constants, methods, and module variables of this module to mod if this module has not already been added to mod or one of its ancestors. Module#prepend_features(mod) → mod => When this module is prepended in another, Ruby calls prepend_features in this module, passing it the receiving module in mod. Ruby’s default implementation is to overlay the constants, methods, and module

How to run Ruby 2.0 with JRuby 1.7?

喜夏-厌秋 提交于 2019-11-30 05:52:15
What is the best way to get JRuby to run in 2.0 mode? For a specific script, you can use the --2.0 option: jruby --2.0 -S rails s For setting 2.0 as the default value, set JRUBY_OPTS : export JRUBY_OPTS=--2.0 You can also set the value in ~/.jrubyrc : compat.version=2.0 来源: https://stackoverflow.com/questions/15281036/how-to-run-ruby-2-0-with-jruby-1-7

What's the best way to return an Enumerator::Lazy when your class doesn't define #each?

冷暖自知 提交于 2019-11-30 05:44:54
问题 Enumerable#lazy relies on your enumerable providing an #each method. If your enumerable doesn't have an #each method you can't use #lazy . Now Kernel#enum_for and #to_enum provide the flexibility to specify an enumeration method other than #each : Kernel#enum_for(method = :each, *args) But #enum_for and friends always construct plain (non-lazy) enumerators, never Enumerator::Lazy . I see that Enumerator in Ruby 1.9.3 offers this similar form of #new: Enumerator#new(obj, method = :each, *args)

Why was the object_id for true and nil changed in ruby2.0?

大兔子大兔子 提交于 2019-11-30 03:38:34
I came across this ruby object_id allocation question sometime back and then read this awesome article which talks about VALUE and explains why object_id of true, nil and false the way they are. I have been toying with ruby2.0 object_id when I found the apparent change that has been made regarding object_id of true and nil. forbidden:~$ ruby -v ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux] forbidden:~$ forbidden:~$ irb irb(main):001:0> true.object_id => 20 irb(main):002:0> false.object_id => 0 irb(main):003:0> nil.object_id => 8 irb(main):004:0> exit forbidden:~$ forbidden:~$ rvm use

Custom Error Handling with Rails 4.0

拈花ヽ惹草 提交于 2019-11-30 01:59:24
I'm building a Ruby on Rails api using Ruby 2.0 and Rails 4.0. My app is almost solely a JSON API, so if an error occurs (500, 404), I want to capture that error and return a nicely formatted JSON error message. I've tried this and also: rescue_from ActionController::RoutingError, :with => :error_render_method def error_render_method puts "HANDLING ERROR" render :json => { :errors => "Method not found." }, :status => :not_found true end In my ApplicationController. Neither of these do the trick (the exceptions are not captured at all). My Googling shows that this changed a lot between 3.1, 3.2

Ruby 2.0 iconv replacement

穿精又带淫゛_ 提交于 2019-11-29 20:59:35
I don't know Ruby but want to run an script where: D:/Heather/Ruby/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- iconv (LoadError) it works somehow if I comment iconv code but it will be much better if I can recode this part: return Iconv.iconv('UTF-8//IGNORE', 'UTF-8', (s + ' ') ).first[0..-2] without iconv . Maybe I can use String#encode here somehow? Iconv was deprecated (removed) in 1.9.3. You can still install it. Reference Material if you unsure: https://rvm.io/packages/iconv/ However the suggestion is that you don't and rather use: string

What is the difference between 'include' and 'prepend' in Ruby?

核能气质少年 提交于 2019-11-29 17:21:09
问题 From the Module Module#append_features(mod) → mod => When this module is included in another, Ruby calls append_features in this module, passing it the receiving module in mod. Ruby’s default implementation is to add the constants, methods, and module variables of this module to mod if this module has not already been added to mod or one of its ancestors. Module#prepend_features(mod) → mod => When this module is prepended in another, Ruby calls prepend_features in this module, passing it the

How to get Rails 4 ActionController::Live streaming working with Thin and Ruby 2? And how do Thin and Puma scale with live streaming?

为君一笑 提交于 2019-11-29 14:33:58
问题 I get it working with Puma, but with Thin I don't get any stream output and I have to kill the server to stop it. I'm testing using tenderlove's initial example outputing the current time: http://tenderlovemaking.com/2012/07/30/is-it-live.html A more general question to me is, is this type of streaming practical in an app with any significant traffic? I imagine there can be easily hunderts if not thousands of users connected to a stream at once in such app. How would Puma scale here? I read

Can't install Ruby 2.0.0-p0 with RVM. Error running 'make -j8'

一世执手 提交于 2019-11-29 10:26:16
I tried to install Ruby 2 using RVM today and it failed. I updated RVM, all my brew formulas and whatnot. This is what I get: admin:/$ rvm install ruby-2.0.0-p0 Searching for binary rubies, this might take some time. No binary rubies available for: osx/10.8/x86_64/ruby-2.0.0-p0. Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies. Installing requirements for osx, might require sudo password. Already up-to-date. Certificates in '/usr/local/etc/openssl/cert.pem' already are up to date. Installing Ruby from source to: /Users/admin/.rvm/rubies/ruby-2.0.0