I don't know any Ruby and am reading some documentationon it now.
A doubt I have just after reading about using code blocks and the "yield" keyword is whether it is possible to pass more than one code block to a function, and use both at will from within the called function.
...
Is there a good way to chain methods conditionally in Ruby?
What I want to do functionally is
if a && b && c
my_object.some_method_because_of_a.some_method_because_of_b.some_method_because_of_c
elsif a && b && !c
my_object.some_method_because_of_a.some_method_because_of_b
elsif a && !b && c
my_object.some_method_because_of_a.some_me...
Is it possible to use time_ago_in_words with i18n.locale?
how?
thanks
...
Is the value returned by ruby's #hash the same across interpreter instances?
For example, if I do "some string".hash, will I always get the same number even if run in different instances of the interpreter? If so, is this also true for all the builtin types (e.g. Hash, FixNum, etc).
...
Hey guys,
I`ve encountered the problem after updating some gems, so basically all older gems are still available but i cant force application use them.
Lets say, i need something like that:
require 'rubygems'
require 'mygem', '0.1.2'
Is there a way to do it?
...
Simple sinatra app:
require 'rubygems'
require 'sinatra'
get '/' do
"Hey"
end
Then:
$ ruby test.rb
And when I hit http://localhost:4567, it drops the connection and I get:
/usr/local/lib/ruby/gems/1.8/gems/thin-1.2.5/lib/thin_parser.bundle: dlopen(/usr/local/lib/ruby/gems/1.8/gems/thin-1.2.5/lib/thin_parser.bundle, 9): no suita...
What advantages and disadvantages do you know of Ruby on Rails polymorphic relationships.
...
I need to set a run-time parameter in postgresql. It is "SET DATESTYLE TO PostgreSQL,European;". Where can I pass that in a Rails Application?
...
I am trying to build an online quote app for roofing. I have a controller called Cost that has squarecost and squaresell. There are other models and controllers for gable, shingle, ridgevent and more with similar fields. These additional models and controllers are the add ons for the quote.
Ideally, sales person would create a new q...
This might be really obvious but I can't find the answer.
How do you get the integer index from named order, like:
{ :first => 0, :second => 1, :third => 2, :fourth => 3 }
Is there something built in to Ruby or Rails that does this?
Thanks.
Update
Thanks for all your responses. Here's the solution I went with:
def index_for(posi...
I am currently struggling with stubbing out a helper method of my Sinatra app from within Cucumber.
I have a Sinatra app with simple session authentication (by cookies) and I want to turn of authentication by stubbing out the logged_in? helper method for my Cucumber scenarios.
There seems to be a problem with Sinatra and Cucumber conce...
somearray = ["some", "thing"]
anotherarray = ["another", "thing"]
somearray.push(anotherarray.flatten!)
I expected
["some","thing","another","thing"]
...
is it possible to force a ruby script to use up to certain amount of CPU and memory.
i dont want the script to be killed when it exceeds this specified amount. i just want it to run within the given constraints.
EDIT:
yes its an endless recursive loop that seems to use lot of CPU.
i noticed that doing return at the end of each recurs...
I've been using Ruby for the first time on a project at my work, so I am still somewhat learning the ropes (and loving every minute of it).
While I understand the point of the map.connect functions in the route.rb file, I don't understand the "resources" and "named route" features of Rails. I have my Rails book here and read it over se...
What is the best way to run simple sql scripts in a database (preferably db implementation agnostically)?
So, for illustration purposes, using your best/suggested way, i'd like to see a script that creates a few tables with names from an array ['cars_table', 'ice_cream_t'], deletes all elements with id=5 in a table, and does a join betw...
It seems that if I use Berkeley DB (DBM) on Ruby, the hash's keys and values must be strings? Can they be other data type?
require 'dbm'
d = DBM.open('test1')
d[1] = 2
d[123] = 456
d[2] = 2.34
d['wa'] = Time.now.to_f
p d.keys
p d.values
Result:
C:\>ruby test_dbm.rb
["wa", "2", "1", "123"]
["1259229787.686", "2.34", "2", "456"]
...
I'm using the RighAWS gem, and mocking at the http level so that the RightAWS code is being executed as part of my tests.
When this happens I get the following output
....New RightAws::S3Interface using per_request-connection mode
Opening new HTTP connection to s3.amazonaws.com:80
.New RightAws::S3Interface using per_request-connecti...
How to identify whether the item of a directory is a file or a directory using Net::SFTP or ruby code?
...
When I call mysqldump from a controller or model I need to fully path the binary, when I call it from Rake I don't need to.
If I do not fully path I get a zero byte file...
I can confirm both processes are run using the same user.
# Works in a controller, model and Rake task
system "/usr/local/mysql/bin/mysqldump -u root #{w.database_...
Using dynamic method calls (#send or #method) the methods visibility is ignored.
is there a simple way to dynamically call a method that will fail calling a private method?
...