ruby-1.9

Why isn't the Ruby 1.9 lambda call possible without the dot in front of the parentheses ?

二次信任 提交于 2019-12-05 10:14:29
问题 I checked out the latest Ruby version, to play a bit with the latest changes. The first thing I tried to do was call a Ruby lambda/block/proc just like you'd do with a Python callable. a = lambda {|x| puts x} a.call(4) # works, and prints 4 a[4] # works and prints 4 a.(4) # same a(4) # undefined method 'a' for main:Object Why isn't the last call possible? Will it ever be? 回答1: AFAIK it's because ruby doesn't let you define the () method for an object. The reason it doesn't let you define the

incompatible character encodings: ASCII-8BIT and UTF-8 in Ruby 1.9

爷,独闯天下 提交于 2019-12-05 05:24:18
I'm getting the following error with my Ruby 1.9 & Rails 2.3.4. This happens when user submits a non-ASCII standard character. I read a lot of online resources but none seems to have a solution that worked. I tried using (as some resources suggested) string.force_encoding('utf-8') but it didn't help. Any ideas how to resolve this? Is there a way to eliminate such characters before saving to the DB? Or, is a there a way to make them show? I don't know much about Ruby (or Rails), but I imagine the problem is caused by a lack of control over your character encodings. First, you should decide

Error 'incompatible character encodings: ASCII-8BIT and UTF-8' due to 8-bit encoding of cookies (Rails 3 and Ruby 1.9)

孤街醉人 提交于 2019-12-05 03:45:46
I moved a web app that was using 1.8.7 to 1.9.2 and now I keep getting incompatible character encodings: ASCII-8BIT and UTF-8 I have the database encoding to UTF-8 and I have also 'config.encoding = "utf-8"'. I saw some ideas as possible workarounds and I added Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_8 But it didn't work either. One specific chunk of code where I am getting this error is %ul.address - @user.address.split(',').each do |line| %li= line.titleize I'm using HAML, I checked line.titleize, and the encoding is UTF-8. Seems that the

What happened with Ruby 1.9.2?

五迷三道 提交于 2019-12-04 21:47:11
I have seen that there is no updates for Ruby 1.9.2. (Only for Ruby 1.9.3 & 2.0). My question is: what happened with 1.9.2? I'm confused if 1.9.3 and 1.9.2 are different branches, or 1.9.3 is the sequel, and if my 1.9.2 app will works with 1.9.3 without problems. If you're talking about updates to deal with CVE-2013-4073, then Ruby-lang.org says : All users are recommended to upgrade to Ruby 2.0.0-p247, 1.9.3-p448 or 1.8.7-p374. Presumably, anyone using MRI Ruby 1.9.2 is able to use MRI Ruby 1.9.3. 来源: https://stackoverflow.com/questions/17688265/what-happened-with-ruby-1-9-2

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

ruby CSV duplicate row parsing

放肆的年华 提交于 2019-12-04 14:36:25
I have some CSV data I need to process, and having trouble figuring out a way to match the duplicates. data looks a bit like this: line id name item_1 item_2 item_3 item_4 1 251 john foo foo foo foo 2 251 john foo bar bar bar 3 251 john foo bar baz baz 4 251 john foo bar baz pat lines 1-3 are duplicates in this case. line id name item_1 item_2 item_3 item_4 5 347 bill foo foo foo foo 6 347 bill foo bar bar bar in this case only line 5 is a duplicate line id name item_1 item_2 item_3 item_4 7 251 mary foo foo foo foo 8 251 mary foo bar bar bar 9 251 mary foo bar baz baz here lines 7 and 8 are

Why do I get a Readline error when trying to start rails console?

我的梦境 提交于 2019-12-04 12:40:37
UPDATE: I probably messed up my system while trying solutions found somewhere else. I started from scratch and Ruby 1.9.3 installed without a hitch. Now to try to get ree-1.8.7 to play nice alongside... I'm trying to install Ruby 1.9.3 using RVM on Kubuntu (11.10 I believe). I've been having plenty of issues with Readline so far, but found the answer to all but this one. I installed Ruby 1.9.3 this way: rvm install 1.9.3 # Install of ruby-1.9.3-p0 - #complete cd ~/.rvm/src/ruby-1.9.3-p0/ext/readline/ ~/.rvm/src/ruby-1.9.3-p0/ext/readline $ ../../ruby extconf.rb --with-editline-dir="/usr" -

Failed to build iconv gem on ruby 1.9.2

谁说胖子不能爱 提交于 2019-12-04 12:33:12
问题 I fail to install the 'iconv' gem, because of weird build errors. I have build the 'libiconv' from source and linked the .h and .dylib into the rvm's include and lib directory. When I run gem install iconv Gem outputs strange build errors: Building native extensions. This could take a while... ERROR: Error installing iconv: ERROR: Failed to build gem native extension. /Users/myusername/.rvm/rubies/ruby-1.9.2-rc2/bin/ruby extconf.rb checking for iconv() in iconv.h... no checking for iconv() in

What are tainted objects, and when should we untaint them?

試著忘記壹切 提交于 2019-12-04 08:25:10
问题 When do Ruby objects need to be made tainted and when should we untaint them? How does the concept of tainted object make a Ruby script run in safe mode? Can anyone elaborate on this to make the concept clear with some code snippets? 回答1: What is Tainted? User input is tainted, by definition. For example: string = gets string.tainted? # => true You can also manually taint an object. string = 'Not yet tainted.' string.tainted? # => false (string = 'Explicitly taint me!').taint string.tainted?

How do I load files from a specific relative path in Ruby?

流过昼夜 提交于 2019-12-04 07:19:47
I'm making a gem for internal use. In it, I load some YAML from another directory: # in <project_root>/bin/magicwand MagicWand::Configuration::Initializer.new(...) # in <project_root>/lib/magicwand/configuration/initializer.rb root_yaml = YAML.load_file( File.expand_path("../../../../data/#{RootFileName}", __FILE__)) # in <project_root>/data/root.yaml --- apple: 100 banana: 200 coconut: 300 I'd rather not depend on the location of data/root.yaml relative to initializer.rb . Instead, I'd rather get a reference to <project_root> and depend on the relative path from there, which seems like a