ruby

Request information from OpenID provider with Ruby

Im currently using ruby-openid gem to work with OpenID providers within my Sinatra application, but i cannot get information fields. This is an example request: openid_url = 'blahblah' resp = openid.begin(openid_url) resp.add_extension_arg('sreg','required','email') resp.add_extension_arg('sreg','optional','fullname,nickname,dob,gender...

How do you convince your manager that your project needs a huge refactoring?

I have joined a rails project as a contractor. The project has been going for more than a year. The code is written by about 10 different developers and most of them are contractors as well. They have different code style. Some of them came from Java. The code has horrible scores with metric_fu. Many functions are very long (100 - 300 li...

How to use String#split() in Ruby?

String is `ex="test1, test2, test3, test4, test5" when I use ex.split(",").first it returns "test1" Now I want to get the remaining items, i.e. `"test2, test3, test4, test5". If I use ex.split(",").last it returns only "test5" how to get the remaining items skipping first one? ...

How does MacPorts install packages? How can I activate a Ruby installation done via MacPorts?

After trying to install ruby19 on my machine (PPC, Mac OSX 10.5.7) using the following commandline sudo port install ruby19 the version of ruby didn't change ruby -v => ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] I assume that i have two versions of it installed on my mac, but how do i use the latest one now? ...

Ruby scope of DATA after __END__

I'm using this Ruby trick with __END__ and DATA to put some data inside my program file: class Foo def initialize() puts DATA.read.inspect end end puts DATA.read.inspect Foo.new __END__ test This generates the following output: "test" "" I had assumed DATA would be the same globally, but inside the class it has no content. ...

Overloading ActiveSupport's default to_sentence behaviour

ActiveSupport offers the nice method to_sentence. Thus, require 'active_support' [1,2,3].to_sentence # gives "1, 2, and 3" [1,2,3].to_sentence(:last_word_connector => ' and ') # gives "1, 2 and 3" it's good that you can change the last word connector, because I prefer not to have the extra comma. but it takes so much extra text: 44 ...

Changing default Ruby arguments

I want to change the default arguments passed to a Ruby function. For example, instead of each time writing [1,2,3].do_stuff(:option => ' my option ') I want to modify the defaults so that I can write [1,2,3].do_stuff What is the simplest, cleanest, most Ruby-like way of changing default parameters? ...

How does one avoid a large number (between 20 and 30) of embedded "if" statements in Ruby?

I've got a massive script with about 20 embedded if statements (Yay!) that is used to parse through a data file. And in a sense, that's correct because the script should not continue operating if any of those evaluations fail. But my gut says there's a more elegant way to accomplish the same thing. I'm familiar with the statemachine plu...

How to declare 8-bit unsigned integer in ruby?

In c++ you can do: uint8 foo_bar How would we do the same thing in ruby? Any alternatives? This post seems close to it maybe someone can explain? ...

Export to dxf from Google Sketchup

How can I write text entities to a dxf file? I found a script that can export Sketchup drawings to dxf files, unfortunately it was ignoring layers and text. I fixed it so it outputs the proper layer, but I cannot figure out how to get it to output the text. I have it to the point where it pops up a message when it comes across a text ...

MIT License For Proprietary App

There are many questions posted with great answers, but nothing I found met my requirements. Hope you guys can help. I will be building a niche social site platform based on Ruby on Rails and will integrate trusted popular gems to save time. The final product will be launched where users can sign-in to use the basic services for free, a...

Strategic Eager Loading for many-to-many relations in Datamapper?

I'm using DataMapper, an open source ORM for ruby, and I have in itch I would like to scratch. At the moment, DataMapper can use Strategic Eager Loading(SEL) for one-to-many relationships, but not many-to-many, where N+1 queries occur. I would like to hack around with making this work correctly, but I cannot find where to do it. So tw...

Ruby and PHP HMACs not agreeing

I'm trying to create an HMAC in Ruby and then verify it in PHP. Ruby: require 'openssl' message = "A522EBF2-5083-484D-99D9-AA97CE49FC6C,1234567890,/api/comic/aWh62,GET" key = "3D2143BD-6F86-449F-992C-65ADC97B968B" hash = OpenSSL::HMAC.hexdigest('sha256', message, key) p hash PHP: <?php $message = "A522EBF2-5083-484D-99D9-AA...

How to halt ruby debugger (like gdb's CTL-C)

Is there a way to tell a running "script/server --debugger" to pause execution and open the debugger prompt (other than sticking a "debugger" statement in my code)? Similar to CTL-C in gdb. I would like to do this, so that I can set a breakpoint in Base.update_attributes without having to put "debugger" in my own function (and having to...

What's the difference between Duby and Juby and why would I need either of them?

According to Charles Nutter, Duby is a static-typed language with Ruby's syntax and Java's type system. Duby supports all Ruby's literals, uses local type inference (only argument types must be declared), and runs as fast as Java (because it produces nearly identical bytecode). But with the advent of invokedynamic, Duby...

Set class inheritance after class delcaration OR setting class inheritance on const_set class

If a class has been previously defined how can I tell it to inherit from a class Parent For instance: class Parent .. end class Klass .. end Now I want it to inherit from Parent I cant re-open the class and set it because I will get a class mismatch error class Klass < Parent .. end Specifically I am trying to find out how...

Usage of Sinatra in Small-Medium apps

Is Sinatra being used for medium-large sized web applications (not just for small apps)? ...

Ruby db Migrate - unknown error

Hi, I have just set up ruby in Aptana studio and am getting the following error when trying to migrate the db. I am a complete noob. Anyone have any idea as to where I need to be looking first? thanks. (See full trace by running task with --trace) >rake db:migrate --trace (in C:/Users/7/My Documents/Aptana Studio Workspace/testing) ** ...

Why is the last expression in my regular expression concatenating to the first?

The language is Ruby, here is my irb session expr = /\Aselect from (\D+)(?: (?:where|&&) (\D+) (\S+) (\S+))*(?: order by (\D+) (asc|desc))?\Z/ => /\Aselect from (\D+)(?: (?:where|&&) (\D+) (\S+) (\S+))*(?: order by (\D+) (asc|desc))?\Z/ /> str = "select from Entity order by value desc" => "select from Entity order by value desc" /> ex...

How to get a rails 2.3.3 application running on Bluehost with fastcgi

Using Your Ruby Gem(s) You will need to add /home/username/ruby/gems to the include path. You can do this by **adding the following code to your script**: $:.push("/home/username/ruby/gems") What script are they referring to? This is vague... Where do I add directories to the ruby include path? ...