ruby1.9

Why Ruby 1.9 allows overriding ! != !~ ?

There were two good reasons why Ruby 1.8 didn't support certain kinds of overloading like ||/or, &&/and, !/not, ?:: Short circuit semantics cannot be implemented with methods in Ruby without very extensive changes to the language. Ruby is hard coded to treat only nil and false as false in boolean contexts. The first reason doesn't ap...

Ruby 1.9 Regex Lookbehind Assertion & Anchors

Ruby 1.9 regex supports lookbehind assertion but I seem to have difficulty when passing anchors in the pattern. When anchors are passed in the lookahead assertion it runs just fine. "well substring! "[/(?<=^|\A|\s|\b)substring!(?=$|\Z|\s|\b)/] #=> RegexpError: invalid pattern in look-behind: /(?<=^|\A|\s|\b)substring(?=$|\Z|\s|\b)/ Do...

Ruby 1.9.2 under RVM and MySQL already initialized constant warnings

When running Rails 3 RC with Ruby 1.9.2.rc2 under RVM I keep getting a very large number of errors from the MySQL driver bundle that look like this: /opt/local/rvm/gems/ruby-1.9.2-rc2/gems/mysql-2.8.1/lib/mysql_api.bundle: warning: already initialized constant MysqlRes /opt/local/rvm/gems/ruby-1.9.2-rc2/gems/mysql-2.8.1/lib/mysql_api.bu...

Geokit Gem 1.5 and Ruby 1.9.2 => "incompatible character encodings: UTF-8 and ASCII-8BIT"

Hi there, I am currently writing a rails app using bleeding edge stuff. Rails3, rSpec2, Ruby 1.9.2 and Geokit 1.5.0. When i try to geocode addresses that have special characters that are not in ASCII-8Bit i get this error: incompatible character encodings: UTF-8 and ASCII-8BIT The Trace is like this: 1) Spot Basic Validations s...

Append row to csv file Ruby 1.9 CSV lib

Using Ruby 1.9 and CSV lib, I can't seem to append a row. The example in the documentation opens the file, and overwrites the row. What is the correct way to append rows to the document? Example from documentation: require 'csv' CSV.open("path/to/file.csv", "wb") do |csv| csv << ["row", "of", "CSV", "data"] csv << ["another", "row...

Installed ruby-1.9 (rvm) and rails 3, mongrel or thin uses system ruby

I am using rvm rvm list rvm rubies jruby-1.5.0 [ i386-java ] jruby-1.5.1 [ i386-java ] ruby-1.8.7-p299 [ i386 ] => ruby-1.9.2-p0 [ i386 ] with: rails -v Rails 3.0.0.rc ruby -v ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux] However, when starting rails (with either webrick or thin), the ruby interpretor used is ru...

Should I use Ruby 1.9.2 with my new web app?

Starting a new web app with Rails 3. I'm still relatively new to web development and have really enjoyed all the internet resources available to me while working in Ruby 1.8.7 and Rails 2.3.5. Any advice against using Ruby 1.9.2 on my new project? ...

Distributed sequential random number generation in Ruby 1.9.2

The Random class in Ruby 1.9.2 is guaranteed to generate random numbers in the same order, given a particular seed and range. For instance: r = Random.new(23) r.rand(100) # 83 r.rand(100) # 40 But suppose I want to generate the next number in the sequence on another computer (without re-generating the earlier numbers i...

How can I choose Ruby version on Heroku?

I use Ruby 1.9.x syntax in my Rails 3 app, but after pushing it to Heroku it crashes due to older Ruby version (1.8). How can I control it? ...

Failed to build iconv gem on ruby 1.9.2

Hello, 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:...

rjb ruby 1.9.1, different behavior in script/server vs script/console

Running into weird errors with Rjb when ran from script/server (using stanfordparser, if that makes a difference): Test code: Rjb::load("/usr/local/stanford-parser/current/stanford-parser.jar") In controller: def test Rjb::load("/usr/local/stanford-parser/current/stanford-parser.jar") render :text => "OK" end When ran from scr...

RVM 1.0.2 fails to build ruby 1.9.2

This fails every time. I ran rvm remove 1.9.2 and then rvm install 1.9.2. The error looks like this: info: Applying patch '' (located at /) error: Error running 'patch -F25 -p1 -f <"/"', please check /Users/peter/.rvm/log/ruby-1.9.2-p0/patch.apply.*.log fail: There has been an error applying the specified patches. Aborting the install...

Can't find OpenSSL headers/libs when installing Ruby1.9 from source

I'm trying to install Ruby 1.9 from source, and I can't seem to get it to figure out where the OpenSSL headers and libraries are located. ruby-1.9.2/ext/openssl/extconf.rb says it can't find openssl/ssl.h -- which I've very definitely installed in ~/.local/include (the corresponding OpenSSL library is in ~/.local/lib). How can I tell Ru...

How to strip out invalid UTF-8 characters in Ruby 1.9

I just upgraded from Ruby 1.8 to 1.9, and most of my text processing scripts now fail with the error invalid byte sequence in UTF-8. I need to either strip out the invalid characters or specify that Ruby should use ASCII encoding instead (or whatever encoding the C stdio functions write, which is how the files were produced) -- how would...

Infamous 'byte sequence" error with local install of gitorious on Ruby 1.9.1

I am trying to install gitorious on my personal server but I am not very familiar with Ruby or the frameworks and scripts involved in getting to the finish line. I am following the following instructions to install gitorious on my CentOS 5.4 server: http://www.tikalk.com/alm/blog/installing-gitorious-centos-55 The site comes up but a...

Does Time.to_i always return number of seconds since EPOCH in UTC?

Is the timezone difference always ignored, regardless in which zone the time is expressed in? Intuitively, the number of seconds passed since EPOCH should be higher for those who are, for example, in UTC+2. However, this seems not to be the case. ...

How to check a String if it's an ASCII or not?

For example something like: "ASCII".is_ascii? # => true "تجربة".is_ascii? # => false ...

Ruby Version Discrepancy when running server

$ ruby -v ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.3.0] $ rails s => Booting WEBrick => Rails 3.0.0 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2010-09-28 13:45:50] INFO WEBrick 1.3.1 [2010-09-28 13:45:50] INFO ruby 1.8.7 (2009-06-08) [universal-dar...

ruby1.9, rails & $SAFE=1

Trying to use $SAFE=1 (just wanted to put some processing in a drb server) make rails unusable: it can't load some paths, data recovered from the DB are tainted, etc. For instance: rails console Loading development environment (Rails 3.0.0) ruby-1.9.2-p0 > $SAFE=1; User.first SecurityError: Insecure operation - file? from .rvm/gems/...

Ruby 1.9 strip not removing whitespace

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