ruby

How to generate bytecode in Ruby 1.9?

How can I generate byetcode from Ruby 1.9?? My intent is to generate bytecode not the source code and ship it along with my application package. I am aware of the JRuby approach but I am facing certain issues there ...

exception with method 'to_query' missing

Hi, I'm trying to install Ruby Bossman, and the following exception happens: /opt/local/lib/ruby/gems/1.8/gems/bossman-0.4.1/lib/bossman/boss.rb:10:in `initialize': undefined method `to_query' for #<Hash:0x1010f0800> (NoMethodError) from /opt/local/lib/ruby/gems/1.8/gems/bossman-0.4.1/lib/bossman/search.rb:12:in `new' from /opt/...

Passing an operator to a function?

Perhaps this just sounds ridiculous but I'm wondering is this possible with Ruby? Basically I have a function... def add a,b c = a + b return c end I'd like to be able to pass the "+" or another operator e.g "-" to the function so that it'd be something like... def sum a,b,operator c = a operator b return c end is this possible...

Ruby getting a particular line from a file?

Is it possible to extract a particular line from a file knowing it's line number? e.g just get the contents of line N as a string from file text.txt ...

Ruby concurrency/asynchronous processing (with simple use case)

I was looking into ruby's parallel/asynchronous processing capabilities and read many articles and blog posts. I looked through EventMachine, Fibers, Revactor, Reia, etc, etc. Unfortunately, I wasn't able to find a simple, effective (and non-IO-blocking) solution for this very simple use case: File.open('somelogfile.txt') do |file| wh...

How to dump an HTTP request from within Sinatra?

Is there a way to dump all incoming requests to a Sinatra application in the exact way the application receives the data? Maybe some sort of Rack middleware? ...

Trying to understand how a Controller uses a Plugin/Module

Ok so I am using some module/lib/plugin (not sure of the exact name), let's say its a authentication/authorization plugin like: http://github.com/technoweenie/restful-authentication class HomeController < ApplicationController some_module_name_here end Now just from adding the code above 'some_module_name_here', I can access t...

What's advantages does the Ruby language have over C#?

I'm read a lot of positives about the Ruby language, people who work in it seem to love it. I'm a C# developer and I find C# a superb language to work in. What advantages does Ruby have over C# (preferably with code examples)? ...

Call Ruby script on multiple input files with wildcard

Hi, I am relatively new to Ruby and need to write a script that will handle mulitple input files. It should be called like so: script.rb -i file* where the directory contains multiple files, like file1.xml, file2.xml and so on. Just a quick question: How will this wildcard be expanded? Do I need to program that in my script? I am usi...

What benefits for the developer does the Ruby language offer that C# does not have?

What benefits for the developer does the Ruby language have that are not available in C# (preferably with code examples)? ...

Embedding message replies inside message parent with mongodb using mongoid

I think it's a best practice to embed replies to a specific message inside that message and I'm trying to implement it using mongoid. here is what I have class Message include Mongoid::Document include Mongoid::Timestamps include Mongoid::Paranoia field :subject field :body field :sender_deleted, :type => Boolean, :defaul...

Use Something like Rails Generator for PHP Development

I want to create a command line based tool for PHP Development. It should do something quite similar based on what the rails generator does as well as integrate with rake, as the rake tasks for the DB should also be available. Or is there a ruby framework that allows to build such generators? ...

Word Count with Ruby

I am trying to figure out a way to count a words in a particular string that contains html. Example String: <p>Hello World</p> Is there a way in Ruby to count the words in between the p tags? Or any tag for that matter? Examples: <p>Hello World</p> <h2>Hello World</h2> <li>Hello World</li> Thanks in advance! Edit (here is my wor...

Tips on understanding Ruby syntax, when to use ?, and unless

Is the keyword unless the same as if? When do you use ?? I've seen: if someobject? I know it checks against nil correct? ...

Lexical analysis in MRI Ruby 1.9.2

I'm learning some compiler theory and practice at the moment. Ruby is my every day language of choice, and so I went to look at its lexer and parse grammar. Does ruby have a separate lexer? If so, which file is it described in? ...

Bunder.require does not work for ActiveRecord in my gem

I just created a new gem (using bundler) and want to add Active Record support. So I added s.add_dependency "activerecord", "~> 3.0" to my gemspec. Then I use Bundler.setup and Bundler.require and thought that I have access to Active Record now, but I haven't. I have to explicitly use require "active_record". Any idea why Bunder.require ...

executing shell command from ruby

This isn't working in ruby and I don't understand why? #!/usr/bin/env ruby exec "sort data.txt > data.sort" data.txt is a comma sepparated file. Anyway.. If I try to execute that line in the shell it works without a problem. When I try to run this script from my script, I get an empty file. ...

How to run a rake task right after rspec initializes the database

I have a Rails 2.2 app that I'm supporting and one thing that needs to be done before the app start is a small rake task to initialize and make sure the database is properly set. How can I get this task run right after rspec initializes the database. I run rspec using the rails spec command. ...

Doing an action in Rails without changing site

Good day... Still a beginner question. I mostly asking to save myself hours of trial and error... I had those already and there was no result. What I wanna do... I have a controller that has an action, of course. I want to send this action two IDs, it should make some database entry of those. No problem, the action works well. But I d...

Layout file on Padrino

Hello guys, Is it possible to use the same layout file across different (mounted) apps without some hackish solution (i.e. sym links) on Padrino ? Cheers, Ze ...