What's the (fastest/cleanest/straightforward) way to convert all keys in a hash from strings to symbols in Ruby?
This would be handy when parsing YAML.
my_hash = YAML.load_file('yml')
I'd like to be able to use:
my_hash[:key]
Rather than:
my_hash['key']
...
I'm trying to write a simple ruby script that will copy a index.tpl to index.html in all of the subdirectories (with a few exceptions). But I'm getting bogged down by trying to get the list of subdirectories
...
Hey,
I have been trying to create a Ruby program that will be running online where a user can guess a number, and it will say higher or lower. I know it will take a random number store in a variable, then run a loop? With conditionals to check?
Im not asking for full code, the basic structure for I can use this to get me going.
Any id...
Hi,
I installed action_mailer_optional_tls for Rails 2.3.2 and Ruby 1.8.6 and I cannot get ActionMailer to send email!
I get the following error:
530 5.7.0 Must issue a STARTTLS
command first
Sadness...anyone had success?
...
I have installed Ramaze (on Windows XP) and it suggested I also install win32console to get coloured log output when it is running.
However, after doing so I get escape codes rather than colours as shown below:
W [2009-04-29 09:02:55 $5064] WARN | : ←[33mNo explicit root folder found, assuming it is C:/Projects/Ruby/Ramaze/Conferences...
Hello,
I'm trying to get the query_string from a Ruby file. For example;
http://localhost/rubyfile.rb?hello=world
I would like to be able to ask what's hello and for it to print "world", but for the life of me I cannot find the correct syntax/way to do it anywhere. Even the Ruby documentation seems dazed.
#!/program files (x86)/ruby/...
I want to obtain an array of ActiveRecord objects given an array of ids.
I assumed that
Object.find([5,2,3])
Would return an array with object 5, object 2, then object 3 in that order, but instead I get an array ordered as object 2, object 3 and then object 5.
The ActiveRecord Base find method API mentions that you shouldn't expect ...
Hello folks;
i'm new with ruby and coding just for fun.
i just found WWW::Mechanize and i loved it at the first time,
There is my question:
i'm connecting to a web site, logging in.
website redirects me to new pages and mechanize deals with all cookie and redirection jobs. bu i cant get the last page. i used firebug and did same job ag...
In Ruby, is there a way to redefine a method of a particular instance of a class using a proc? For example:
class Foo
def bar()
return "hello"
end
end
x = Foo.new
y = Foo.new
(Something like):
y.method(:bar) = lambda { return "goodbye" }
x.bar
y.bar
Producing:
hello
goodbye
Thanks.
...
I have a field called sui in one of my models. It stands for "Standard User Identifier." When there are validation errors on the field, Rails prints "Sui is required" or "Sui is already taken."
How can I tell Rails that 'sui'.titleize is "SUI"? I looked at Inflector.human, but that isn't quite right.
...
Right now I have two fields for cost. One for dollars and one for cents. This works, but it is a bit ugly. It also doesn't allow the user to enter the term "free" or "no cost" if they want. But if I only have one field, I might have to make my parser a bit smarter. What do you think?
On the server side, I combine dollars and cents t...
I have an array like so:
["marblecake", "also", "the", 1337]
I would like to get back a string which contains each element of the array prefixed by some specified string, then joined together by another specified string. For example,
["marblecake", "also", "the", 1337].join_with_prefix("%", "__")
should result in
# => %marblecake_...
I have an application with a lot of database relationships that depend on each other to successfully operate the application. The hinge in the application is a model called the Schedule, but the schedule will pull Blocks, an Employee, a JobTitle, and an Assignment (in addition to that, every Block will pull an assignment from the databas...
I'm having trouble getting ThinkingSphinx to recognize my conditions.
My Discussion model includes the following code:
define_index do
indexes [subject, body], :as => :text
indexes replies.body, :as => :reply_text
set_property :delta => true
end
And as expected this search
Discussion.search "handy"
returns any discussion wit...
I understand the subtle differences between require, load and autoload in Ruby, but my question is, how do you know which one to use?
Other than being able to "wrap" a load in an anonymous module, require seems to be preferred.
But then autoload allows you to lazy load files -- which sounds fantastic but I'm not sure practically what ...
First of all, I'm a Rails newbie. I can hold my own in Ruby, but Rails is a whole different story for me. I like the development speed Rails offers me, but I can't seem to make peace with the existing documentation.
For all of my forms so far, I used form_for, with an instance for the model I needed to create ( for example, submitting a...
is it better to develop ruby on rails in a) windows b) linux or c) mac. why ?
edited :
the reason why i am asking this is that i heard that developing ruby on rails in windows is not as stable/good compared when you used ruby on rails in mac. (not sure though if that is true or not).
plus the fact that David Heinemeier Hansson (cre...
How do I use CSS with RoR? When I link externally, I'm never able to see the files. I cp'd the .css file to every folder I could think of...views, controller, template, and nothing seems to work.
What do I need to do to enable external CSS files with a rails application? I'm new to rails, so forgive me if this is basic.
Solution:
P...
Hi,
I was going through the Programming Ruby book and Im having problem understanding the following concepts:
The authors talk about "transient exceptions" that may occur in the code and then suggest a creation of your own exception object to handle them. I dont think i fully understand what a transient error is and when is it appro...
I'm new to Ruby on Rails, and I'm in the process of setting it up on my OS X system. Most guides seem to recommend using MacPorts to install Ruby and RubyGems, then using RubyGems from there on to install gems. I've noticed that MacPorts also offers many gems (though they're missing some and others seem a few releases behind), and I'm wo...