ruby-2.0

Ruby 2.0 Bytecode Export / Import

大兔子大兔子 提交于 2019-12-04 18:17:26
问题 I've been reading about the new ruby 2.0 features, and found that it will support bytecode import / export: Ruby 2.0 is expected to make it simple to save pre-compiled Ruby scripts to bytecode representations and to then run these directly. I've installed ruby-2.0.0-p0, but I didn't find any information on how to export the bytecode (or generally documentation on that matter). Is this feature already implemented, and if so, how do I use it? I'm also wondering about some of the details. Is

Access STDIN of child process without capturing STDOUT or STDERR

倾然丶 夕夏残阳落幕 提交于 2019-12-04 15:47:53
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 capture either STDOUT or both STDOUT and STDERR . So what should I use? If you’re on a platform that

Rails 4 - strong parameters concept involvement in spree-2.1

核能气质少年 提交于 2019-12-04 12:09:20
问题 How to add new fields for spree::user in Spree-2.1 + Rails4 ? Like my old customization: ========================== Spree::User.class_eval do attr_accessible :f_name, :l_name :gender validates :f_name, :presence => true, :length => {:maximum => 25} validates :l_name, :presence => true, :length => {:maximum => 20} end new work with strong parameters: ================================ module Spree UserRegistrationsController.class_eval do private def spree_user_params params.require(:spree_user)

Can procs be used with case statements in Ruby 2.0?

我与影子孤独终老i 提交于 2019-12-04 02:59:07
I remember something about procs being allowed in case statements in Ruby 2.0, but I can't google it. I tried checking Ruby 2.0.0 NEWS and How to write a switch statement in Ruby . I also visited http://ruby-doc.org , but the link it had for keywords was for Ruby 1.9, not Ruby 2.0. Are procs allowed in case statements? Phrogz Yes. 2.0.0p0 :001> lamb = ->(x){ x%2==1 } #=> #<Proc:0x007fdd6a97dd90@(irb):1 (lambda)> 2.0.0p0 :002> case 3; when lamb then p(:yay); end :yay #=> :yay 2.0.0p0 :003> lamb === 3 #=> true 2.0.0p0 :007> lamb === 2 #=> false However, this is no different than 1.9.1 since Proc

Custom Error Handling with Rails 4.0

喜夏-厌秋 提交于 2019-12-03 18:50:33
问题 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

Rails 4.1 AWS Beanstalk cannot find secret key base

跟風遠走 提交于 2019-12-03 17:16:58
I am trying to upload my rails project on AWS Beanstalk. I've already run eb init, eb start and configured the database settings to point to RDS. After I pushed using git aws.push and waited for AWS server to be started, the link provided says: "502 Bad Gateway nginx" In the logs ------------------------------------- /var/app/support/logs/passenger.log ------------------------------------- App 6861 stderr: [ 2014-05-29 13:26:59.1308 6893/0x00000001e50050(Worker 1) utils.rb:68 ]: *** Exception RuntimeError in Rack application object (Missing `secret_key_base` for 'production' environment, set

Google plus insert activity on stream

对着背影说爱祢 提交于 2019-12-03 17:09:18
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, plus.login, plus.me, plus.media.upload, plus.profiles.read, plus.stream.read, plus.stream.write, plus

Ruby 2.0.0 String#Match ArgumentError: invalid byte sequence in UTF-8

折月煮酒 提交于 2019-12-03 10:45:43
问题 I see this a lot and haven't figured out a graceful solution. If user input contains invalid byte sequences, I need to be able to have it not raise an exception. For example: # @raw_response comes from user and contains invalid UTF-8 # for example: @raw_response = "\xBF" regex.match(@raw_response) ArgumentError: invalid byte sequence in UTF-8 Numerous similar questions have been asked and the result appears to be encoding or force encoding the string. Neither of these work for me however:

Comparability Issue rails 4 beta, ruby 2.0.0, mongoid

时光怂恿深爱的人放手 提交于 2019-12-03 08:14:35
问题 I am creating a test application using following versions of rails, ruby and mongoid. rails 4 beta ruby 2.0.0 mongoid 3.1.2 My GemFile looks like this gem 'rails', '4.0.0.beta1' ruby '2.0.0' gem 'mongoid', '~> 3.1.2' gem 'bson_ext' But when i run bundle on console I get following error. Bundler could not find compatible versions for gem "activemodel": Fetching gem metadata from https://rubygems.org/........... Fetching gem metadata from https://rubygems.org/.. Resolving dependencies...

Better way to turn a ruby class into a module than using refinements?

二次信任 提交于 2019-12-03 03:41:48
问题 Module#refine method takes a class and a block and returns a refinement module, so I thought I could define: class Class def include_refined(klass) _refinement = Module.new do include refine(klass) { yield if block_given? } end self.send :include, _refinement end end and the following test passes class Base def foo "foo" end end class Receiver include_refined(Base) { def foo "refined " + super end } end describe Receiver do it { should respond_to(:foo) } its(:foo) { should eq("refined foo") }