class ArrayMine < Array
def join( sep = $,, format = "%s" )
collect do |item|
sprintf( format, item )
end.join( sep )
end
end
=> rooms = ArrayMine[3, 4, 6] #i couldn't understand how this line works
print "We have " + rooms.join( ", ", "%d bed" ) + " rooms available."
i have tried the same with String, but it ...
Hi,
i'm using RESTFUL authentication on a rails application. The signup/login is working fine. I'm trying to display the username (based on what they logged in with) on the 'members' page they are re-directed to. for example, "Welcome back John!"
any ideas?
thanx
...
I thought that mechanize follows redirection by default ... by my script ends at the redirection page. How can I handle this?
require 'rubygems'
require 'mechanize'
agent = WWW::Mechanize.new
page = agent.get("http://www.vbulletin.org/forum/index.php")
login_form = page.form_with(:action => 'login.php?do=login')
login_form['vb_logi...
Hey all,
I have a mondoDB with data in it at the moment which I am querying with Ruby on Rails. I am looking to index the database to speed things up a bit.
I read the mongoDB documentation and followed the instructions on how to add a index, like so:
db.collection.ensureIndex({"key": 1})
This returns true and returns this in the co...
Hi,
I am very new to Ruby technology. In my current Project the Backend application is develooping ruby and Fortend is developing Flex with HTTPServices. I try to find any where how the Flex will call to Ruby. Please any one haing sample code, please send me asap.
Actually i have a httpService in my applcation like..
And i could n...
I've installed ruby-1.8.6-p383 with RVM. System ruby is 1.9.1_p378-1
I'm getting the wrong date from Date.today and DateTime.now when using ruby 1.8.. Whereas Time.now is correct:
irb(main):002:0> DateTime.now.to_s
=> "2126--1-10618T11:23:43+00:00"
irb(main):004:0> Date.today.to_s
=> "2126--1-10618"
irb(main):005:0> Time.now
=> Thu Jan...
I have a ruby project, and the database host and port might be different on dev and production. I need a way to get different values for those into my scripts for the two environments.
The project should be complete - so there should be some way to specify default values. I don't want a clone to be missing the config files. So ignoring...
Hi there,
I just stumbled upon something i don't quite understand. I know that variables in ruby are references. So that awesome stuff is possible. But when i pass a variable to a method, it behaves strangely:
my_var_a = "nothing happend to me"
my_var_b = "nothing happend to me"
def parse_set(my_var_set)
my_var_set = "my value chang...
In Ruby, suppose I have a class Foo to allow me to catalogue my large collection of Foos. It's a fundamental law of nature that all Foos are green and spherical, so I have defined class methods as follows:
class Foo
def self.colour
"green"
end
def self.is_spherical?
true
end
end
This lets me do
Foo.colour # "green"
...
Hi. I need to query my database using mysql native functions such as YEAR(date) or NOW().... This works on staging and on production environments but it won't work in my development environment because of SQLite's lack of support to these functions.
Can you help?
Thank you.
...
Is it possible to access the text after __END__ in a ruby file other than the "main" script?
For example:
# b.rb
B_DATA = DATA.read
__END__
bbb
.
# a.rb
require 'b'
A_DATA = DATA.read
puts 'A_DATA: ' + A_DATA
puts 'B_DATA: ' + B_DATA
__END__
aaa
.
C:\Temp>ruby a.rb
A_DATA:
B_DATA: aaa
Is there any way to get at the "bbb" from b...
According to the YAML documentation it's possible to pass a hash of options to the .to_yaml method.
Currently when I pass the options as suggested by the documentation it's not working, the hash is being ignored.
irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> user = { "1" => { "name" => "john", "age" => 44 } }
user.to_yaml
=>...
The method below exists in the Redcloth gem.
My question is: what does the construction "to(RedCloth::Formatters::HTML)" mean? "to" isn't a method in the class, nor in the superclass (wich is String class).
Cheers. Christian.
def to_html( *rules )
apply_rules(rules)
to(RedCloth::Formatters::HTML)
end
...
What vulnerabilities are possible in ruby with $SAFE = 4? Right off the bat I know that XSRF is possible because the attack has nothing to do with "tainted variables" but rather where http request originates from. I know that using weak cryptographic algorithms like md5() won't be picked up. Do you know of any others? Code examples a...
I am trying to break down the following string:
"@command Text1 @command2 Text2"
in Ruby. I want to take out "Text1" and "Text2" in an array. To do this I am using the scan method and using this:
text.scan(/@* (.*?)(@|$)/)
However, when run, the script is pulling the @ symbol in the middle as a separate match (presumably because th...
Given I have an array of 3 strings:
["Extra tv in bedroom",
"Extra tv in living room",
"Extra tv outside the shop"]
How do I find the longest string all strings have in common?
...
I have an array of strings, not many (maybe a few hundreds) but often long (a few hundred chars).
Those string are, generally, nonsense and different one from the other.. but in a group of those string, maybe 5 out of 300, there's a great similarity. In fact they are the same string, what differs is formatting, punctuation and a few wor...
Using the index method, I'm trying to find if a value exists using a certain variable, and if that variable doesn't exist, then try another variable; a little something like this (3rd line below):
a = [ "a", "b", "c" ]
a.index("b") #=> 1
a.index("z" or "y" or "x" or "b") #=> 1
..meaning that if "z" is not found in the array, then ...
Would it be safe to delete ruby from my mac (the version that came preinstalled), and replace it with a link to ruby1.9, and do the same with irb and gem?
Is there anything specifically that might be an issue?
...
Hi there,
I'm planning to perhaps purchase an android phone, and would love to be able to script some simple apps in Ruby on it. I found this article from back in August where the author was able to get the scripts working, but since I'm not a Java head, I had a hard time understanding all the steps.
http://amazing-development.com/arch...