ruby-1.9

Ruby 1.9 strip not removing whitespace

*爱你&永不变心* 提交于 2020-02-20 08:49:28
问题 Im doing some screen scraping and im getting back a string that appears to end with whitespace but neither string.strip or strip.gsub(/\s/u, '') removes the character. Im guessing it's a character encoding issue. Any suggestions? 回答1: I think, there are a lot of "space characters". You can use something like this: my_string.gsub("\302\240", ' ').strip 回答2: You can try this: my_string.gsub(/\A[[:space:]]+|[[:space:]]+\z/, '') This should remove all space characters from the beginning and the

Ruby 1.9 strip not removing whitespace

谁说胖子不能爱 提交于 2020-02-20 08:49:12
问题 Im doing some screen scraping and im getting back a string that appears to end with whitespace but neither string.strip or strip.gsub(/\s/u, '') removes the character. Im guessing it's a character encoding issue. Any suggestions? 回答1: I think, there are a lot of "space characters". You can use something like this: my_string.gsub("\302\240", ' ').strip 回答2: You can try this: my_string.gsub(/\A[[:space:]]+|[[:space:]]+\z/, '') This should remove all space characters from the beginning and the

Model namespace issue in rails

℡╲_俬逩灬. 提交于 2020-02-05 04:13:46
问题 I am having an issue with namespaces in Rails 3.1. I have a class, let's call it a. #/app/models/a.rb class a #some methods def self.method_from_a #does things end end But I also have another class that has the same name in a different namespace. #/app/models/b/a.rb class b::a def method return a.method_from_a end end When I call b::a.method though I get: NameError: uninitialized constant b::a::a I am sure it is a simple solution, I am just missing it. 回答1: Prefix a with :: : class b::a def

Model namespace issue in rails

回眸只為那壹抹淺笑 提交于 2020-02-05 04:13:43
问题 I am having an issue with namespaces in Rails 3.1. I have a class, let's call it a. #/app/models/a.rb class a #some methods def self.method_from_a #does things end end But I also have another class that has the same name in a different namespace. #/app/models/b/a.rb class b::a def method return a.method_from_a end end When I call b::a.method though I get: NameError: uninitialized constant b::a::a I am sure it is a simple solution, I am just missing it. 回答1: Prefix a with :: : class b::a def

How do I debug ruby-ldap when a method only returns false?

拟墨画扇 提交于 2020-01-25 08:57:07
问题 My goal is to move an account to another OU. My understanding is that the following code should do the job. However, it returns false . There is no error, warning or exceptions. How do I debug why this isn't working? secure_ldap.rename( olddn: self.dn, newrdn: "CN=#{self.cn}", delete_attributes: true, new_superior: "#{ou}" ) 回答1: Well, one approach might be to add pry and pry-byebug to your application. Modify your code to include binding.pry then run your application: Frame number: 0/0 From:

Regex “\w” doesn't process utf-8 characters in Ruby 1.9.2

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-24 12:41:49
问题 Regex \w doesn't match utf-8 characters in Ruby 1.9.2. Anybody faced same problem? Example: /[\w\s]+/u In my rails application.rb I've added config.encoding = "utf-8" 回答1: Define "doesn't match utf-8 characters"? If you expect \w to match anything other than exactly the uppercase and lowercase ASCII letters, the ASCII digits, and underscore, it won't -- Ruby has defined \w to be equivalent to [A-Za-z0-9_] regardless of Unicode. Maybe you want \p{Word} or something similar instead. Ref: Ruby 1

How to mix a module into an rspec context

时光怂恿深爱的人放手 提交于 2020-01-22 05:51:19
问题 How can I mix a module into an rspec context (aka describe ), such that the module's constants are available to the spec? module Foo FOO = 1 end describe 'constants in rspec' do include Foo p const_get(:FOO) # => 1 p FOO # uninitialized constant FOO (NameError) end That const_get can retrieve the constant when the name of the constant cannot is interesting. What's causing rspec's curious behavior? I am using MRI 1.9.1 and rspec 2.8.0. The symptoms are the same with MRI 1.8.7. 回答1: You can use

Getting error for libxml2.2.dylib “file is not of required architecture”

这一生的挚爱 提交于 2020-01-14 10:40:50
问题 I'm trying to use rvm to install Ruby 1.9.2 on my Mac running Snow Leopard. My .bash_profile contains ARCHFLAGS="-arch x86_64" To install ruby, I run: rvm install 1.9.2 -C --enable-shared I get an error during compiling. Here is the make.error.log: [2010-01-20 10:03:00] make ld: in /usr/local/lib/libxml2.2.dylib, file is not of required architecture collect2: ld returned 1 exit status make[1]: *** [../../.ext/i386-darwin10.2.0/tcltklib.bundle] Error 1 make: *** [mkmain.sh] Error 1 EDIT: I

Rails + Ruby 1.9 “invalid byte squence in US-ASCII”

泪湿孤枕 提交于 2020-01-13 19:11:42
问题 After upgrading to ruby 1.9 we began to notice pages failing to render from the rails template renderer when a user used a non-ASCII character. Specifically "é". I was able to resolve this issue on one of our staging servers, but I have not been able to reproduce the fix on our production server. The fix that seemed to work the first time: Converted the database from latin1 to utf8 using the convert_charset tool available here: http://www.mysqlperformanceblog.com/2009/03/17/converting

Rails + Ruby 1.9 “invalid byte squence in US-ASCII”

淺唱寂寞╮ 提交于 2020-01-13 19:10:31
问题 After upgrading to ruby 1.9 we began to notice pages failing to render from the rails template renderer when a user used a non-ASCII character. Specifically "é". I was able to resolve this issue on one of our staging servers, but I have not been able to reproduce the fix on our production server. The fix that seemed to work the first time: Converted the database from latin1 to utf8 using the convert_charset tool available here: http://www.mysqlperformanceblog.com/2009/03/17/converting