ruby

linux-Ruby - run a ruby application as a command

Hi, I want to run a lib of ruby files from the command prompt from anywhere in a command line. I have the Main.rb program which instantiates classes from other ruby files. I store the class path of my lib in the .zshrc. Then I run the Main.rb but it is not able to load the required ruby files (files in my lib folder) and throws this er...

ActionController::MethodNotAllowed (Only get and post requests are allowed.):

Not sure what's going on. I've used the following bit of code to try and edit the name of a category, but I'm getting the error message above. My code for the form and submit for the edit is: - <% form_for :category, :url => categories_url(@category),:html => { :method => :put } do |f| -%> <p>Name: <br /><%= f.text_field :name, :size =>...

Is there a way to say match 1 or more instances of a defined subsequence/grouping?

require 'rubygems' require 'differ' original = "Epic lolcat fail bellmead drive!" current = "Epic wolfman fail bellmead dr!" diff = Differ.diff_by_word(current, original).to_s puts diff # => "Epic {"lolcat" >> "wolfman"} fail bellmead {"drive" >> "dr"}! diff =~ /(\{"[a-zA-Z0-9]*" >> "[a-zA-Z0-9s]*"\})/ puts "#{$1} to #{$2} #{...

Custom << method

class Foo def initialize @bar = [] end def changed_callback puts "Bar has been changed!" end def bar @bar end def bar=(a) @bar = a self.changed_callback() # (hence why this doesn't just use attr_accessor) end def bar<<(a) @bar.push(a) self.changed_callback() end end f = Foo.new() f.bar...

ruby unit testing framework UI

Hi , Is there an inbuilt UI support in the ruby unit test framework. Can i show the results of my unit test in UI? regards ...

ruby bitwise or

Here is code def tmp a = ancestors.first(ancestors.index(ActiveRecord::Base)) b = a.sum([]) { |m| m.public_instance_methods(false) | m.private_instance_methods(false) | m.protected_instance_methods(false) } b.map {|m| m.to_s }.to_set end I thought | is bitwise OR operator. So how come b ...

regional problem with fastercsv

Hi, what is the right way to check csv separator character, either using ";" or "," in a different computer regional setting ? I want my fastercsv able to parse both of them without complaining at all, what is the right way to do it ? ...

Ruby: how does running this block through instance_eval work?

I have recently seen some code that I do not completely understand. There is an array named foo that contains instances of Proc objects. Then, an env object is used to setup an environment to work in: env = Object.new foo.each do |f| env.instance_eval &f # what happens here? end What exactly happens when you open the object with i...

Working examples of EM::Iterator

Does anyone have any working examples of EM::Iterator? The only examples I can find seem to be copies of (or point back to): http://yardoc.org/docs/eventmachine-eventmachine/EventMachine/Iterator I don't see any instances of EM::Iterator in EventMachine's Rdoc, so I'm not sure if it's an old class that has been removed or not. I gen...

How can I determine if my process is being run interactively?

Is there a standard(ish) POSIX way of determining if my process (I’m writing this as a Ruby script right now; but I’m curious for multiple environments, including Node.js and ISO C command-line applications) is being run in an interactive terminal, as opposed to, say, cron, or execution from another tool, or… so on and so forth. Specifi...

Programming thunderbird Email Client?

Anyone has C#/Ruby/Python/Java or Perl scripts to get all the emails in a folder in Thunderbird client and download all the attachments? I have more than 200 resumes as attachment kept in Resumes folder of thunderbird and I need to download the attachment and categories them. Any API reference to program thunderbird would be great.. I ...

How to get exit status with Ruby's Net::SSH library?

I have a snippet of code, simply trying to execute a script on a remote server, in the event that it fails, I'd like to make a follow-up call, imagine this: require 'rubygems' require 'net/ssh' require 'etc' server = 'localhost' Net::SSH.start(server, Etc.getlogin) do |ssh| puts (ssh.exec("true") ? 'Exit Success' : "Exit Failure") ...

How to Block images in watir ?

I am watir for some data fetching job and I dont really require any images to loaded. So I was wondering if it is possible since I want to speed up the process. ...

method_missing override is not working

I wrote a convenience ActiveRecord extension to delegate methods to a base object (based on multi-table inheritance) class ActiveRecord::Base def self.acts_as(base) class_eval %Q{ def method_missing(method, *args, ActiveRecord::Base belongs_to :my_object acts_as :my_object end # base class class MyObject < ActiveRecor...

How to load modules with an iteration and execute a method in RUBY

Hello, i would like to load modules dynamically and execute a method for each module loaded: The modules are in a directory called modules/ modules/ModA.rb module ModA def run puts "module A" end end modules/ModB.rb module ModB def run puts "module B" end end Main.rb class Main def start Dir.glob("modules...

Ruby object in my JavaScript file

I have a Ruby object and I want to use that object in JavaScript. I haven't seen that type of thing, but I want a Ruby object in my .js file. Is this possible? Thanks in advance ...

"gem install wxruby" but require 'wxruby' won't work

I did gem install wxruby on Win 7 and in Ruby 1.8.6 require 'rubygems' require 'wxruby' but it will say c:/ruby1.8.6/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- wxruby (LoadError) from c:/ruby1.8.6/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' f...

Library for electrical network simulation

I'm searching for a free and open source library for electrical network simulation. In (Per preference order) : Python, Ruby, Javascript, PHP, C++ (with Qt if it exist) or bash (ahah). Do you know one ? ...

How to write a wxRuby program that will just drawText and setPixel without going into main_loop?

I want to write a program that will constantly compute numbers, and draw on the window canvas, including drawing text and setting pixels. So the program probably cannot go into an event loop (the main_loop), because that will stop the computation of numbers. Is there a way just to draw the items without an event loop? Or, should a thr...

Help! check_in': undefined method `push' for nil:NilClass (NoMethodError)

Hi Im getting an core error which is really standard I suppose in Ruby but dont know what to make of it. I have a program that I have written. Its purpose is to register guests at a camping. You have a menu with 5 different options. 1. Checkin. When i do this I get a undefined method generateParkingLot' for #<Camping:0x10030a768> (NoMe...