ruby1.9

can't start script/console with Ruby 1.9 and Rails 2.3.4

Hi, I'm trying to start the console (irb) in Ruby 1.9 with Rails 2.3.4. I have two versions installed of Ruby (1.9 & 1.8.6) and I run the Ruby 1.9 by calling: rake19, ruby19, gem19...etc And they work fine in all situations except this! it seems that its trying to load Ruby 1.8 instead! Do you know how I can change that? Macintosh-10:...

Is it possible to define a block with default arguments in Ruby?

This question deals with optional arguments passed to a Ruby block. I'm wondering if it's also possible to define arguments with default values, and what the syntax for that would be. At first glance, it appears that the answer is "no": def call_it &block block.call end call_it do |x = "foo"| p "Called the block with value #{x}" e...

invalid multibyte char (US-ASCII) with Ruby on Rails

Hi, I'm using Ruby 1.9.1 with Rails 2.3.4 My application is to handle text input If I try something like (the inside quotation marks look different) text = "”“" I get the following error: #<SyntaxError: /Users/tammam56/rubydev/favquote/lib/daemons/twitter_quotes_fetch.rb:54: invalid multibyte char (US-ASCII) /Users/tammam56/rubydev...

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

Hi, 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 t...

preserving visibility when doing an alias_method_chain on attr_accessor in Ruby 1.9

I'm trying to port a library from ruby 1.8. I didn't write the library. I can change the API if absolutely necessary, but it does have a fair number of users I would prefer not to inconvenience. Here's the problem simplified: require 'rubygems' require 'activesupport' class Foo private def self.attr_accessor_with_magic(*attrs) ...

alternatives to Hash#index that works without warning in both Ruby 1.8 and 1.9

I've got some ruby code that I'm converting to Ruby 1.9. One warning I get is Hash#index is deprecated; use Hash#key But Hash#key is not defined in Ruby 1.8, so I can't use that directly. Does anybody have a good alternative? I've got a couple of options (which I'll post as answers so you can vote), but I'm hoping for better. ...

Can Ruby 1.9 used with Rails by a Ruby/Rails beginner?

About half a year ago, when I started to learn Ruby and Rails, I first tried Ruby 1.9 but I soon gave up, because at that time nothing worked out of the box and almost every helping blog or tutorial was designed for Ruby 1.8. What about now? (Dec 2009) Is it possible to get an existing Rails application running by a Ruby and Rails begin...

How to correctly uninstall Ruby 1.9.1

Hi:) I have manually set Ruby 1.9.1. I have installed it via ./configure --prefix=/opt make make install The target 'uninstall' does not exist in generated Makefile ... How to do uninstallation correctly? PS: I also believe that it is necessary to remove all the gems. For this I use #!/bin/sh gem list --local | grep [^\*] | cut -d '...

making ruby 1.9 the default ruby on ubuntu

Is there any way, on Ubuntu 9.04, to install ruby 1.8 as ruby1.8 (or get rid of it altogether) and have ruby 1.9 be the default ruby? ...

ruby 1.9: how do I get a byte-index-based slice of a String?

I'm working with UTF-8 strings. I need to get a slice using byte-based indexes, not char-based. I found references on the web to String#subseq, which is supposed to be like String#[], but for bytes. Alas, it seems not to have made it to 1.9.1. Now, why would I want to do that? There's a chance I'll end up with an invalid string should ...

Ruby 1.9, YAML, and string encodings: how to lead a life of sanity?

It seems to me that the YAML library that ships with ruby 1.9 is encoding-deaf. What this means is that when generating YAML, it'll take any string of bytes, and escape any byte sequence that doesn't output clean ASCII. That's lame, but acceptable. My problem is the other way around. When loading content from said YAML dump. In the ex...

Using Ruby 1.9.1, how could I access this string's characters one at a time?

I don't know how else to explain, so I'll give you List of greek words with english derivatives. Look at the a table, please, first column. Notice there are words like ἄβαξ. Using Ruby 1.9.1, which has better encoding support than Ruby 1.8, how could I iterate over each character forming that word? For example, I'd like to get the letter...

Matching words in UTF-8 encoded string with Ruby 1.9.1

I want to match all individual words in given string, provided that String is UTF-8 encoded, and then I spellcheck each word. Everything works with my code provided it's english-only text, but if there are some, say, German characters, my words are split in two on these characters. How can I match single words from text, that contain lat...

Rails + Ruby 1.9 "invalid byte squence in US-ASCII"

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 ti...

Can I set the default string encoding on Ruby 1.9?

This might sound minor, but it's been driving me nuts. Since releasing an application to production last Friday on Ruby 1.9, I've been having lots of minor exceptions related to character encodings. Almost all of it is some variation on: Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8 We have an ...

Error installing Ruby 1.9 with RVM under Snow Leopard

Hello I've got some problems to get Ruby 1.9.2 compiling with rvm (Ruby Version Manger) under Snow Leopard. I want everything possibly to be 64-Bit so I already added ARCHFLAGS="-arch x86_64" to my .bash_profile. Then, when running: rvm install 1.9.2 -C --enable-shared I get an error during compiling. Here is the make.error.log: ...

str.each in Ruby isn't working

I'm Learning Ruby. I found the method String#each at http://ruby-doc.org/core/classes/String.html. When I try using it... irb(main):001:0> "hello\nworld".each {|s| p s} NoMethodError: undefined method `each' for "hello\nworld":String ...but I get that NoMethodError. I'm using Ruby 1.9.1p253 so I don't think I'm using an old versi...

Ruby 1.9 hash with a dash in a key

In ruby 1.9 there is a way to define this hash with the new syntax? irb> { a: 2 } => {:a=>2} irb> { a-b: 2 } SyntaxError: (irb):5: syntax error, unexpected tLABEL { a-b: 2 } ^ with the old one, it's working: irb> { :"a-b" => 2 } => {:"a-b"=>2} ...

write csv in ruby 1.9 and CSV::Writer

hi, i have a code that works fine with ruby 1.87 but dont works with ruby 1.9. It says that CSV::Writer is undeclared but it still part of the rdoc. Does the csv api changed, after the fastercsv merge, or not? my code: require 'csv' def self.export_csv file_name = File.join(RAILS_ROOT, 'public','csv',"#{start_date_f}_#{end_date_f}.c...

Can't install ruby 1.9.1 on MacOSX 10.6

Hi all, I can't seem to be get Ruby installed on my Mac. These are the steps I've taken so far: Downloaded the package from Ruby's site (http://www.ruby-lang.org/en/downloads/) Unpacked it running { tar xzvf ruby-1.9.1-p376.tar.gz } Went into the new ruby folder, and configured using {./configure} This is where the error happens. ...