ruby

How to add a single backslash character to a string in Ruby?

I want to insert backslash before apostrophe in "children's world" string. Is there a easy way to do it? irb(main):035:0> s = "children's world" => "children's world" irb(main):036:0> s.gsub('\'', '\\\'') => "childrens worlds world" ...

Is Test::Unit still relevant in rails?

I am learning Rails the age old way. By reading Agile Web Development with Rails (3rd Edition) as a starting point. I am currently in the chapter that teaches Testing. I am also aware of other BDD Testing framework such as RSPec. So I was wondering if frameworks such as RSpec, Cucumber, Shoulda replace the need for knowing/using Test::Un...

How do I access my rails database from a task in lib/tasks?

I am developing an app that needs to send text messages, so I have carrier information stored in a database. I also need that information in an XML file for client side code to read. To make this happen, I am writing a script that reads the carrier information from the DB and creates an XML file in the config directory. I felt this sc...

How to diagnose/trace "sendsig: useracc failed." problem in HP-UX

I am trying to compile Ruby 1.9.1-p0 on HP-UX. After a small change to ext/pty.c it compiles successfully, albeit with a lot of warning messages (about 5K). When I run the self-tests using "make test" it crashes and core-dumps with the following error: sendsig: useracc failed. 0x9fffffffbf7dae00 0x00000000005000 Pid 3044 was k...

Is Ruby really an interpreted language if all of its implementations are compiled into bytecode?

In the chosen answer for this question about Blue Ruby, Chuck says: All of the current Ruby implementations are compiled to bytecode. Contrary to SAP's claims, as of Ruby 1.9, MRI itself includes a bytecode compiler, though the ability to save the compiled bytecode to disk disappeared somewhere in the process of merging...

If monkey patching is permitted in both Ruby and Python, why is it more controversial in Ruby?

In many discussions I have heard about Ruby in which people have expressed their reservations about the language, the issue of monkey patching comes up as one of their primary concerns. However, I rarely hear the same arguments made in the context of Python although it is also permitted in the Python language. Why this distinction? ...

How to request for gzipped pages from web servers through ruby scripts?

I have a ruby script that goes and saves web pages from various sites, how do i make sure that it checks if the server can send gzipped files and saves them if available... any help would be great! ...

CouchDB views erroring out

I've been playing with CouchDB (and the RelaxDB ruby library) but creating a view and then trying to access it causes a nasty non specific error. I stepped back a step because I thought RelaxDB might be incompatible with the CouchDB version I'm using(0.8.1), but even when I create a new database and equivalent views and call it by manual...

How would I write this ftp client soap consumer in Ruby?

I have a project that I'm starting soon and thought it might be fun to write it in Ruby. Here are the basic requirements: Must be run as a background process Will be running all day Process should sleep for 10 seconds then check 6 different ftp servers for new files From 4 of the servers, just pickup the files then ftp to a different ...

How to access the variables defined in environment.rb in RoR ?

I want to create a thread object in environment.rb and use it in some other action of some controller. How should I do it? Thanks in advance. ...

Besides dynamic typing, what makes Ruby "more flexible" than Java?

I've been using Java almost since it first came out but have over the last five years gotten burnt out with how complex it's become to get even the simplest things done. I'm starting to learn Ruby at the recommendation of my psychiatrist, uh, I mean my coworkers (younger, cooler coworkers - they use Macs!). Anyway, one of the things they...

Is there a way to get all variables in Ruby?

Is there a way I can find all the variables in Ruby that begin with a particular string? For example, I have the following variables in my ruby program ret_d = 1 ret_d2 = 23 Now, is there a function that will return ["ret_d","ret_d2"]? The problem is that I do not have the set of all variables. Thanks. ...

Writing supybot plugins not in python?

What's the best way to write a supybot plugin in ruby? Or other language (not python)? ...

What are the coolest Ruby on Rails features, why choose it?

Before I asked this question I had a look through the search results for 'Ruby on Rails' here on SO. Couldn't find much, but the following (found on this page) amused me Personally, I started using .html, moved onto php, tried ruby (hated it), discovered Python / DJango.. and have been happy ever since. Now here's the deal. I have ...

fixnum and prime numbers in ruby

Before I set about to writing this myself, has anyone seen a ruby implementation of the following behavior? puts 7.nextprime(); #=> 11 puts 7.previousprime(); #=> 5 puts 7.isprime(); #=> true Obviously this kind of thing would be ugly for large numbers but for integers never exceeding a few thousand (the common instance fo...

Torn Between learning PHP [insert framework here] and Ruby on Rails

Here's my situation: I'm an ASP.NET Developer first and foremost. That's not going to change anytime soon. I have built my small business on it. With that being said, I'm looking to add other technologies to my arsenal. Not just for learning purposes, but to one day be able to offer clients an alternative solution. For this reason, ...

Ruby Garbage Collection: Mark non-exported variables

I have several structs bound with Data_Wrap_Struct to ruby objects and I also supplied mark() and free() functions. When I manually start the GC or just wait until it jumps in my ruby objects are killed. Nothing new so far. The strange thing is: When I try to protect these objects with rb_gc_register_address() nothing happens - my o...

Is 'c' said to be a character or a string in Ruby - or both?

char hello[] = "hello"; #C hello = ['h', 'e', 'l', 'l', 'o'] #Ruby If I output the class of hello[0] in Ruby, it says "String". This is because single quoted Strings exist in Ruby and there does not seem to be the notion of a char type. The other day I said to my coworker that he had an array of characters and he said "no I don't, I ha...

Shoes Layout

I'm trying to produce a shoes layout like the following: the text is giving me a problem. I tried: stack { flow { check stack { para 'text 1' para 'text 2' } para 'Free' } } But that doesn't work at all. Any ideas? ...

Authlogic and acts_as_authentic problem

We am using authlogic for my user authentication.It works on other machines but i am getting the error Extracted source (around line #20): 7: <%= link_to "Home", "/", :title => 'Home', :class => 'header-logo' %> 18: 19: 20: <span style="padding-left:850px;"> <% if current_user %> 21: <%= link_to "My Accoun...