ruby

Ruby Enumeration and RETURN_ENUMERATOR - Questions Regarding Ruby's C Internals

I'm a bit confused about how Ruby handles the creation of Enumerators. Block-based iteration makes sense and is working for me; I am still confused how the return of an Enumerator is supposed to function code-wise. Here is the code I am working with: VALUE rb_RPRuby_Sender_Kernel_each_backtrace_frame( int argc, ...

Ruby: retrieve contents of URL as string

For tedious reasons to do with hpricot, I need to write a function that is passed a URL, and returns the whole contents of the page as a single string. I'm close. I know I need to use open-uri, and it should look something like this: require 'open-uri' open(url) { # do something mysterious here to get page_string } puts page_string ...

Routing HTTP verbs in Rails

I'm trying to route only an http verb. Say I have a comments resource like so: map.resources :comments And would like to be able to destroy all comments by sending a DELETE /comments request. I.e. I want to be able to map just the http verb without the "action name" part of the route. Is this possible? Cheers ...

Why cant there be classes inside methods in Ruby ?

Can I create Ruby classes within functions bodies ? I seem to be getting error which tells me its not allowed but I think it should be as classes are too objects here. class A def method class B end end end This fails with error 'class definition inside method body. If we cant, why cant we create classes inside...

how to open a file in ruby

path1="c:/amit_150000.txt" v=1 fs=File.open("$path"+"#{v}",'w') Now I have to open that file but I am not able to. Please tell me the problem. ...

extract all email addresses from some .txt documents using ruby

Hi all, I have to extract all email addresses from some .txt documents. These emails may have these formats: [email protected] {a, b, c}@abc.edu some other formats including some @ signs. I choose ruby for my first language to write this program, but i don't know how to write the regex. Would someone help me? Thank you! ...

how to solve this equation in ruby

path1="c:/kabab.txt" path2="c:/kabab2.txt" for v in 1..2 puts "#{path}"#{v}" end I would like to create a file, but I'm not able to do that. ...

Ruby Struct - Performance Overhead?

Is there any performance overhead that you take on when using Structs (as compared to Arrays, Hashes, etc.) in Ruby? ...

Send email with attachment in Ruby

I need to send an email with an attachment via Ruby. Been searching around but haven't found any simple script example to do this. Closest I've found is ActionMailer but that seems to require a bunch of other scripts to to run. (NOTE: I am not using Ruby on Rails) ...

Ruby require 'rack' fails

Hello, I'm trying to install redmine and I have a problem with phusion-passenger. Installer fails on dependencies saying that rack is missing. I've investigated the code to check where it looks for it, but I've found a line: require 'rack' that is enclosed in what seems to be rubys try-catch block. I've already installed rack through ...

run method in testcase.rb ,what type should the argument be of

For the run(result) method in test/unit/testcase.rb what attribute type should my result be of .It will store the result from the error and assertions from the TestCase class i dono if it should be TestCase object or something dono.. could someone help ...

ruby soap client without wsdl

Hi, I need to write a soap client that is capable of sending and receiving soap messages. This soap service does not have an associated WSDL file and soap4r and savon both seem to require one. I have an example of what I need to do in Java, see the link below. http://community.cecid.hku.hk/index.php/product/article/writing_hermes_2_w...

Newbie to RegEx..

I have this sample string : ≪! [If Gte Mso 9]>≪Xml> ≪Br /> ≪O:Office Document Settings> ≪Br /> ≪O:Allow Png/> ≪Br /> ≪/O:Off... And I would like to target specifically anything that begins in an "" and ends in a ">", and replace it with no-space "". Been using Rubular, but I'm having a tricky time learning ...

Ruby's Truncate unsanitizes MS Word code..

Curious if anyone ever noticed this, but I have a WYSIWYG that users occassionally paste from word into. There is a word sanitizer, but not everyone's a genius. If I parse that text somewhere else, it comes out right. But if I truncate it, then the msword code appears. Does anyone know why truncate unsanitizes this || does anyone know ...

how to stop sinatra from running?

If ruby myapp.rb starts sinatra previewing at localhost:4567, how can I programatically stop/halt/kill it? Terminal command (other than Ctrl-C), or Rake tasks would be fine. I need to incorporate this into a Rake task or terminal. Thanks ...

rails - Finding intersections between multiple arrays

Hi, I am trying to find the intersection values between multiple arrays. for example code1 = [1,2,3] code2 = [2,3,4] code3 = [0,2,6] So the result would be 2 I know in PHP you can do this with array_intersect I wanted to be able to easily add additional array so I don't really want to use multiple loops Any ideas ? Thanks, Alex...

Piping stdin to ruby script via `myapp | myscript.rb`

I have an app that runs continuously, dumping output from a server and sending strings to stdout. I want to process this output with a Ruby script. The strings are \n-terminated. For example, I'm trying to run this on the command line: myapp.exe | my_script.rb ...with my_script.rb defined as: while $stdin.gets puts $_ end I ult...

How do I run code before and after a method in a sub class?

My first thoughts are some thing like this: class AbstractBuilder attr_reader :time_taken def build_with_timer started_at = Time.now build @time_taken = Time.now - started_at end def build raise 'Implement this method in a subclass' end end class MyBuilder < AbstractBuilder def build sleep(5) end en...

Streaming HTTPs using Ruby

I wanted to open a https connection and keep it unclosed. I will be getting an xml document, which I will be saving in a file as it gets streamed. I tried net/https, but I was able to use Net::HTTP::Get.new() method, which stops after getting one response. My primary use is to save the xml that I am downloading into chunks of file. A...

Install Ruby 1.9.2 on Mac OSX 10.6 with 32bit version

Hi, I have started with Ruby app development and I see that there are many Ruby Gems which don't work on 64bit (which I have installed right now). Their moderators have suggested to use 32bit build for Snow Leopard(10.6). I went to Ruby's website, but didn't find a separate installer for Ruby 1.9.2 for 32bit 10.6 So, how do I fix it? ...