ruby

Ruby gem for unix 'at' command

I've found the whenever gem quite useful for working with cron from Ruby. Does anyone know of a similar project for at/batch? ...

Implementing Server Push

Read about Server push here. I want to push data to client from my web application in real time. I was looking at TCP sockets as one of the options. For HTTP I found a variety of frameworks for Java, PHP, Python and others over here. However I don't know whether any of these support Push. What options and frameworks would you suggest...

Is 'yield self' the same as instance_eval?

Is there any difference if you define Foo with instance_eval: . . . class Foo def initialize(&block) instance_eval(&block) if block_given? end end . . . or with 'yield self': class Foo def initialize yield self if block_given? end end In either case you can do this: x = Foo.new { def foo; 'foo'; end } x.foo...

erb: output repeats if template contains a method definition

I expected to see the word "test" appear in the output once and the word "hello" appear once. But I'm puzzling over the fact that if I do this, the word "test" is displayed twice. <div> <h3>test</h3> </div> <% def helo %> <% "hello" %> <% end %> <%= helo %> I assume there's a simple explanation for this related to some quirk o...

What's the best cross platform approach (Windows/Mac) to deploy a simple service/daemon (with simple UI)

Hi, I'm getting confused re the range of options for development & deploying some simple code & UI to both Windows & Mac. Can anyone assist re a good direction here. I do like Ruby, however if it makes sense to move away from this (e.g. java, c#) then so be it. Which development option would people suggest for this? REQUIREMENTS ...

Difference between "and" and && in Ruby?

What is the difference between && and and operators in Ruby? ...

ParseTree will not work with ruby 1.9. Why?

As per this parsetree will not work in ruby 1.9 . I do not have computer science background but have been programming for a few years. Can someone explain in a little extra detail why parsetree will not work in ruby 1.9. ...

Multiple MySQL queries with Ruby

Hi, I'm having troubles with MySQL queries in Ruby. I use 'mysql' gem. Configuration is stored in a separate yml file and loaded into @conf variable. This is my code: # connect to the database Mysql::new(@conf['sql_host'], @conf['sql_user'], @conf['sql_password'], @conf['sql_base']) # it's ok when we're doing this my.query("SELECT * ...

Rails Has One relation

I have a simple database that has the following relation. Each Server has one Game. now the table Game is just a list of the different games that are possible to have on the server. However, when I do a @server.game, I get a SQL exception because it's trying to find the server's INSTANCE of it's game (Select * from games where games.s...

Why does the second 'p arg' report the Foo instance?

class Foo def with_yield yield(self) end def with_instance_eval(&block) instance_eval(&block) end end f = Foo.new f.with_yield do |arg| p self # => main p arg # => #<Foo:0x100124b10> end f.with_instance_eval do |arg| p self # => #<Foo:0x100124b10> p arg # => #<Foo:0x100124b10> end Why does the second...

Ruby / Rails - Reverse Migration - DDL to Ruby Code

Any tools in Ruby or Rails that would allow me to extract from database all the table schema and generate Ruby equivalent "DLL" statements? Something that would allow me to port schema from say Microsoft SQL Server to Postgres, or MySQL to Sqlite. ...

How to insert header in generated files

I can't find how to have generated files contain a header (with copyright info, etc.) in Rails 2.3. I'd like all files generated automatically by the Rails Generator to have this header at the beginning of the file. How to do it? ...

How do I test XML equality in Ruby?

Clearly I need to (a) convert both strings to canonical XML or (b) compare their parse-trees. The following doesn't work because the document object returned doesn't have a sensible == defined. Nokogiri.XML(doc_a) == Nokogiri.XML(doc_b) Nor does the following, because Nokogiri's to_xml leaves some internal whitespace: Nokogiri.XML(d...

rails error "you may have ambiguous routes"

I'm having an issue with my routes and the name of the path it generates. Or I'm naming it wrong in the view or something... not totally sure. My relationships in my models are as follows: class Client < ActiveRecord::Base has_many :users has_many :elements, :through => :users end class Element < ActiveRecord::Base belongs_to :u...

string formatting, remove leading chars

I have a string like this: 00:11:40 or 00:02:40 how do I formated so that I can always get rid of the leading zero(s) and colon(s), so it looks like this 11:40 or 2:40 ...

GMail threading, IMAP and Ruby

I am using the Ruby IMAP library to get a GMail conversation. The way that GMail threads conversations is via "Message-ID" and "In-Reply-To" message headers. For example: In-Reply-To: <[email protected]> Message-ID: <[email protected]> I cannot figure ou...

What's an example of when you use a Proc or Lambda in a Ruby web application?

I'm having a hard time imagining a practical use for Procs and Lambdas in a web app. Does anyone have an example of a situation in your code where they come in handy? ...

How to populate a field based on selection in previous field?

In the form that we designed, we have a "States" field that allows its users to select multiple states at a time. There is a "City" field which should be populated as per the selection in the "State" field. The values in the "City" field are correctly populated if only one state is selected. However, it is not showing correctly when mult...

I have two versions of Ruby (1.8.7 and 1.9) installed how to specify which one for rails? or does it matter

Hello, I have Ruby 1.8.7 and 1.9 install. I run the different ones by specifying ruby or ruby1.9 when running commands. for example ruby --version or ruby1.9 --version however when I want to create new rails application the command available is rails such as: rails my_app_name How do I specify when I call the 'rails' command t...

Btrieve/Pervasive db and Ruby

Is there any solution to work with Btrieve/Pervasive db from Ruby level? Any gem? Maybe somebody have some experience with such a thing? Or maybe use some Java libs through Jruby? I've never used Jruby ...