ruby-2.0

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

大憨熊 提交于 2019-12-03 02:18:00
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: regex.match(@raw_response.force_encoding("UTF-8")) ArgumentError: invalid byte sequence in UTF-8 or regex

Does multibyte character interfere with end-line character within a regex?

ⅰ亾dé卋堺 提交于 2019-12-03 01:51:44
With this regex: regex1 = /\z/ the following strings match: "hello" =~ regex1 # => 5 "こんにちは" =~ regex1 # => 5 but with these regexes: regex2 = /#$/?\z/ regex3 = /\n?\z/ they show difference: "hello" =~ regex2 # => 5 "hello" =~ regex3 # => 5 "こんにちは" =~ regex2 # => nil "こんにちは" =~ regex3 # => nil What is interfering? The string encoding is UTF-8, and the OS is Linux (i.e., $/ is "\n" ). Are the multibyte characters interfering with $/ ? How? The problem you reported is definitely a bug of the Regexp of RUBY_VERSION #=> "2.0.0" but already existing in previous 1.9 when the encoding allow multi

Comparability Issue rails 4 beta, ruby 2.0.0, mongoid

时光总嘲笑我的痴心妄想 提交于 2019-12-02 21:54:37
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... Bundler could not find compatible versions for gem "activemodel": In Gemfile: mongoid (~> 3.1.2) ruby depends

Ruby string prepend '\' character

我怕爱的太早我们不能终老 提交于 2019-12-02 19:44:01
问题 why ruby is prepends '\' character while I am trying to run below code. It is happening with only '#$' It is happening with all ruby version. puts '#$' => '\#$' or '#$' => '\#$' or 'mypassord#$123' => 'mypassord\#$123' Please share you experience here. Is it a ruby problem or anything? 回答1: No it is not a ruby problem. It is your problem. Since #$foo can be interpreted as interpolation of the global variable $foo , it is necessary to escape the # character. That is why there is a backslash.

Ruby string prepend '\\' character

ぐ巨炮叔叔 提交于 2019-12-02 10:57:36
why ruby is prepends '\' character while I am trying to run below code. It is happening with only '#$' It is happening with all ruby version. puts '#$' => '\#$' or '#$' => '\#$' or 'mypassord#$123' => 'mypassord\#$123' Please share you experience here. Is it a ruby problem or anything? No it is not a ruby problem. It is your problem. Since #$foo can be interpreted as interpolation of the global variable $foo , it is necessary to escape the # character. That is why there is a backslash. To be more precise, there is no possibility of interpolation with the string "#$" ( $ is an invalid global

Install SASS using gem on Windows 8

眉间皱痕 提交于 2019-12-01 06:39:36
I am trying to install SASS on Windows 8 x64, but still getting errors, even when my firewall is switched off. I make this command: C:\Ruby200-x64\bin>gem install sass (or C:\Ruby200-x64\bin>ruby -S gem install sass) I get this response: ERROR: Could not find a valid gem 'sass' (>= 0), here is why: Unable to download data from http://rubygems.org/ - Errno::EACCES: Per mission denied - connect(2) (http://rubygems.org/latest_specs.4.8.gz) Does anybody know how to solve this problem, please? This is work for me. Try this... gem source -a http://rubygems.org/ answer y to the question "Do you want

Install SASS using gem on Windows 8

为君一笑 提交于 2019-12-01 04:35:33
问题 I am trying to install SASS on Windows 8 x64, but still getting errors, even when my firewall is switched off. I make this command: C:\Ruby200-x64\bin>gem install sass (or C:\Ruby200-x64\bin>ruby -S gem install sass) I get this response: ERROR: Could not find a valid gem 'sass' (>= 0), here is why: Unable to download data from http://rubygems.org/ - Errno::EACCES: Per mission denied - connect(2) (http://rubygems.org/latest_specs.4.8.gz) Does anybody know how to solve this problem, please? 回答1

Rails 4 server fails, Ruby 2.0 segmentation fault, Abort trap 6

拟墨画扇 提交于 2019-12-01 02:12:42
问题 I just started going through railstutorial.org and getting my development environment setup. When I got to the section 1.2.5 to run rails server for the fist_app, I type the command and the following printed out: $ rails server /Users/aaronpflower/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/sqlite3- < 1.3.8/lib/sqlite3/sqlite3_native.bundle: [BUG] Segmentation fault ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-darwin13.2.0] Then followed by 500 lines of text 0 enumerator.so 1

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

此生再无相见时 提交于 2019-11-30 21:45:37
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) Unfortunately that constructor has been completely removed in Ruby 2.0. Also I don't think it was ever

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

六月ゝ 毕业季﹏ 提交于 2019-11-30 17:20:35
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 pry-byebug 1.1.1+ works with ruby 2.0.0-p247. It's a fork of pry-debugger & works with ruby 2.0+ only. gem 'pry