Questions tagged [ruby-1.8]

For issues relating to developing in Ruby, version 1.8. If your question applies to Ruby in general, use the tag [tag:ruby].

Ruby is an open-source dynamic object-oriented interpreted language created by Yukihiro Matsumoto (Matz) in the 1990s.

Related tags:

139 questions
153
votes
11 answers

Ruby: require vs require_relative - best practice to workaround running in both Ruby <1.9.2 and >=1.9.2

What is the best practice if I want to require a relative file in Ruby and I want it to work in both 1.8.x and >=1.9.2? I see a few options: just do $LOAD_PATH << '.' and forget everything do $LOAD_PATH << File.dirname(__FILE__) require…
GreyCat
  • 15,483
  • 17
  • 70
  • 107
102
votes
4 answers

What is the difference between Ruby 1.8 and Ruby 1.9

I'm not clear on the differences between the "current" version of Ruby (1.8) and the "new" version (1.9). Is there an "easy" or a "simple" explanation of the differences and why it is so different?
salt.racer
  • 20,273
  • 14
  • 41
  • 50
29
votes
1 answer

Parse Date string in Ruby

I have a String 20120119 which represents a date in the format 'YYYYMMDD'. I want to parse this string into a Ruby object that represents a Date so that I can do some basic date calculation, such as diff against today's date. I am using version…
Kevin
  • 5,192
  • 14
  • 56
  • 82
25
votes
5 answers

(Ruby) Getting Net::SMTP working with Gmail...?

Does anyone have any quality (and up-to-date) information regarding sending mail via Gmail using Ruby's Net::SMTP? I've seen several examples -- most dating from 2007 to mid-2008 and none of them work for me. I need more current examples that use…
humble_coder
  • 2,645
  • 7
  • 32
  • 44
19
votes
1 answer

Ruby require 'file' and relative location

So I'm writing some rspec tests and I'm embarrassed at my lack of Ruby understanding. I have a file structure that looks like the following: GUI_Tests/Tests/test_spec.rb GUI_Tests/windows_gui.rb GUI_Tests/upload_tool.rb when I run spec for the…
Bobby B
  • 2,232
  • 3
  • 24
  • 31
13
votes
1 answer

Is this a bug in Method#to_proc? (Ruby 1.8.7)

Given the following method that takes one argument: def foo(arg); p arg; end I can call it with an empty array: foo([]) # prints [] I can also save it as a Method object and call that with an empty array, with the same…
Sam Stokes
  • 14,071
  • 7
  • 34
  • 32
9
votes
3 answers

How to dynamically create instance methods at runtime?

[ruby 1.8] Assume I have: dummy "string" do puts "thing" end Now, this is a call to a method which has as input arguments one string and one block. Nice. Now assume I can have a lot of similar calls (different method names, same arguments).…
Emiliano Poggi
  • 22,882
  • 7
  • 49
  • 64
8
votes
2 answers

Can I dynamically define a Ruby method that takes a block?

I know that I can dynamically define methods on a class using define_method, and that I specify the parameters this method takes using the arity of the block. I want to dynamically define a method that accepts both optional parameters and a block.…
andrewdotnich
  • 14,133
  • 7
  • 35
  • 56
8
votes
2 answers

Spawning an independent thread or process in Ruby

I may be approaching this in the wrong direction, so any help would be appreciated. I have a Ruby script which, amongst other things, starts up an executable. I want to start this executable - currently being triggered using system "" - and then…
Lee Winder
  • 797
  • 10
  • 34
8
votes
3 answers

Load File from parent directory

I'm working with Ruby 1.8 and I have script that I want to call but it's in a parent folder. Below is the structure: maindir/ neededscript.rb subdir/ subdir2/ myscript.rb How can I require neededscript.rb from inside myscript.rb?
zulqarnain
  • 1,572
  • 1
  • 13
  • 32
7
votes
2 answers

How to get character's Unicode in Ruby 1.8.7?

To get character's Unicode in Ruby 1.9.2, I use ord: "я".ord # => 1103 (It's a Russian letter) How could I get the Unicode in Ruby 1.8.7 ?
Misha Moroshko
  • 148,413
  • 200
  • 467
  • 700
7
votes
1 answer

Why this code is not compiling on ruby 1.9 but is on ruby 1.8?

Sorry for the title, I don't know how this syntax is called. For instance: ary = [ [11, [1]], [22, [2, 2]], [33, [3, 3, 3]] ] # want to get [ [11, 1], [22, 2], [33, 3] ] Ruby 1.8 ary.map{|x, (y,)| [x, y] } #=> [[11, 1], [22, 2], [33,…
oldergod
  • 14,370
  • 7
  • 54
  • 81
6
votes
2 answers

Stopping a Distributed Ruby Service

I have a script that starts up a DRb service, before spawning a handler object and waiting via DRb.thread.join. I would like the script to run until explicitly killed, so I added trap "INT" do DRb.stop_service end which successfully stops the…
kfb
  • 5,342
  • 6
  • 32
  • 46
6
votes
1 answer

Why does this code work in ruby 1.8 and not ruby 1.9?

This piece of code: def func *; end [func "hello"] is parsed without error in Ruby 1.8.7, but returns a syntax error: syntax error, unexpected ']', expecting '}' in Ruby >= 1.9. I looked through What is the difference between Ruby 1.8 and Ruby…
Aman Gupta
  • 537
  • 1
  • 7
  • 22
5
votes
2 answers

Supporting Ruby 1.9's hash syntax in Ruby 1.8

I'm writing a Ruby gem using the {key: 'value'} syntax for hashes throughout my code. My tests all pass in 1.9.x, but I (understandably) get syntax error, unexpected ':', expecting ')' in 1.8.7. Is there a best practice for supporting the 1.8.x? Do…
JackCA
  • 4,775
  • 4
  • 23
  • 26
1
2 3
9 10