ruby-1.9

C1 or C2 coverage tool for ruby [duplicate]

你说的曾经没有我的故事 提交于 2019-12-20 13:33:09
问题 This question already has answers here : Does C1 code coverage analysis exist for Ruby? [closed] (5 answers) Closed last year . Is there any tool for C1 or C2 code coverage for Ruby (1.9)? SimpleCov supports only C0, but maybe there is another tool. I'm aware that a similar question has been asked here, but it was a couple years ago and I hope that something has changed. 回答1: No, currently there is no tool that does that. There is also no technical limitation that avoids one to implement it,

How to convert a Net::HTTP response to a certain encoding in Ruby 1.9.1?

≯℡__Kan透↙ 提交于 2019-12-18 15:35:33
问题 I have a Sinatra application (http://analyzethis.espace-technologies.com) that does the following Retrieve an HTML page (via net/http) Create a Nokogiri document from the response.body Extract some info and send it back in the response. The response should be UTF-8 encoded So I came to the problem while trying to read sites that use windows-1256 encodings like www.filfan.com or www.masrawy.com. The problem is the result of the encoding conversion is not correct though no errors are thrown.

How to specify output file encoding in Ruby?

无人久伴 提交于 2019-12-18 01:27:14
问题 How can I set the encoding of a file when using a File#open ? 回答1: Here's an example that outputs a file in the UTF-16LE encoding: open("data.txt", "w:UTF-16LE") Ruby looks at the encoding of the string you are writing, and transcodes as necessary. Here's a very detailed blog post describing mechanics with excellent examples (see the section called "The Default External and Internal Encodings"). 回答2: That blog also has a bunch of great information about character encoding with Ruby, including

Is there a way in ruby 1.9 to remove invalid byte sequences from strings?

前提是你 提交于 2019-12-17 18:26:16
问题 Suppose you have a string like "€foo\xA0" , encoded UTF-8, Is there a way to remove invalid byte sequences from this string? ( so you get "€foo" ) In ruby-1.8 you could use Iconv.iconv('UTF-8//IGNORE', 'UTF-8', "€foo\xA0") but that is now deprecated. "€foo\xA0".encode('UTF-8') doesn't do anything, since it is already UTF-8. I tried: "€foo\xA0".force_encoding('BINARY').encode('UTF-8', :undef => :replace, :replace => '') which yields "foo" But that also loses the valid multibyte character € 回答1

How do I get the class of a BasicObject instance?

穿精又带淫゛_ 提交于 2019-12-17 17:41:31
问题 I have a script that iterates using ObjectSpace#each_object with no args. Then it prints how many instances exist for each class. I realized that some classes redefine the #class instance method, so I had to find another way to get the actual class; Let's say it's stored in variable "klass" , and klass === object is true. In Ruby 1.8 I could do this, assuming Object wasn't monkeypatched: Object.instance_method(:class).bind(object).call This worked for ActiveSupport::Duration instances: # Ruby

Rails 3 invalid multibyte char (US-ASCII)

社会主义新天地 提交于 2019-12-17 10:19:51
问题 I found a similar post here but I can't solve the problem anyway. I got this /home/fra/siti/Pensiero/db/seeds.rb:32: invalid multibyte char (US-ASCII) /home/fra/siti/Pensiero/db/seeds.rb:32: invalid multibyte char (US-ASCII) /home/fra/siti/Pensiero/db/seeds.rb:32: syntax error, unexpected $end, expecting ')' ... ed il valore della vita, si è malati", :user_id => 1, :cat... The problem is into this string :body => "Nel momento in cui ci si chiede il significato ed il valore della vita, si è

How to use a variable from one method to other in a same class in Ruby?

妖精的绣舞 提交于 2019-12-13 07:57:40
问题 I am new to Ruby. I have a below code in my controller. Desired Behaviour :- I want to display validation error string to my views on edit page. So I am putting those errors in a variable. When validation fails then I want to use that variable in my edit method, so that I can display that on my edit page view. Observed behaviour :- There is a variable @vpinerr in create method. I wan to use that variable in edit method. I have tried to use the class variable (@@vpinerr) and initialized it

How does enum#with_object differ from enum#each_with_object?

允我心安 提交于 2019-12-12 15:08:50
问题 The documentation says: enum#each_with_object :- Iterates the given block for each element with an arbitrary object, obj, and returns obj enum#with_object:- Iterates the given block for each element with an arbitrary object, obj, and returns obj But when I tried the below on the both constructs, one gave me the output as expected but the others didn't. So I suspect there is a difference between those two constructs. Using each_with_object %w(foo bar).each_with_object({}) { |str, hsh| hsh[str]

Why is my rake call causing an 'undefined method `source_index`' error?

江枫思渺然 提交于 2019-12-12 13:49:54
问题 I am trying to run bundle exec rake db:migrate then encountered the following error. bundle exec rake db:migrate --trace ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment rake aborted! undefined method `source_index' for Gem:Module C:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.17/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path' C:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.17/lib/initializer.rb:298:in `add_gem_load_paths' C:/Ruby193/lib/ruby

Connection failed for google open_id using omniauth

为君一笑 提交于 2019-12-12 09:44:16
问题 I am trying to add open-id functionality to my app, I am using omniauth and omniauth-openid gems for same. I have done the installation steps added it to initializer as middleware, require 'omniauth-openid' require 'openid/store/filesystem' Rails.application.config.middleware.use OmniAuth::Builder do provider :open_id, :store => OpenID::Store::Filesystem.new('/tmp') end and a routes for andling callback match '/auth/:provider/callback' => 'callback#myauthentication' when I try to hit this url