In Ruby, everything is supposed to be an object. But I have a big problem to get to the function object defined the usual way, like
def f
"foo"
end
Unlike in Python, f is the function result, not the function itself. Therefore, f(), f, ObjectSpace.f are all "foo". Also f.methods returns just string method list.
How do I access th...
i have a database Country filled with (obvious) contries. now i would like to display them in the select_tag in my view (like a drop down list).
i tried puttin in options_for_select sth like @show_me_the_countries_mama.each do |f| ('[' + f.printable_name + ']' + ','). this would list countries each one of them in [] brackets and with s...
What do I need to do to get number_to_human_size to work in a script outside of rails?
...
What's the most efficient way to build a cache with arbitrary Ruby objects as keys that are expired based on a least recently used algorithm. It should use Ruby's normal hashing semantics (not equal?)
...
Is it possible to set the display precision of a float in Ruby?
Something like:
z = 1/3
z.to_s #=> 0.33333333333333
z.to_s(3) #=> 0.333
z.to_s(5) #=> 0.33333
Or do I have to override the to_s method of Float?
...
I have a Rails web application with a select box:
<%= select_tag :foo %>
I'm looking to write a function in the controller which would populate this select box with some values. What code would I need to write in order to do that?
It's fine if the values are hard coded into the function.
def populate
# what goes here?
end
...
Is there a way to just pull the year (or any other element... month, day, etc) from the site.time property that is available to your template file in Jekyll?
Right now it returns, for example: Sat Dec 19 14:07:03 -0700 2009
Any help is appreciated. Thanks!
...
I'm learning Ruby on Rails with the AWDR book and have had to be specific about which version of Rails and Ruby that I am running on my local machine. I have just discovered that I need to roll back from ruby 1.8.7 to ruby 1.8.6 here. I also needed to roll back Rails to support the scaffold method so I could start the tutorial easily.
...
I am developing Ruby application with Netbeans because of its automatic code completion and its inline help system.
But when Netbeans try to autocomplete the source code while typing, the typing looks like stopped.
Is there any way to improve this experience? Maybe by disabling the code completion, inline help system, syntax highligh...
run the following, and its supposed to return the company name. The xpath works in firefox, and it returns the company name. however in nokogiri, this isn't happening, it jsut returns empty string!
require 'rubygems'
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open('http://www.careerbuilder.com/JobSeeker/Jobs/JobDetails...
What applications can you make with the programming language Ruby? Can you name a few commercial/famous ones written only in Ruby?
What I'd really like to know is can you just learn Ruby instead of C/C++ to make commercial software e.g web server, photoshop, desktop applications, even an operating system etc.
Except Ruby on Rails whic...
I want to let a user of a web app enter a URL and then pass that URL onto curl. I'd rather use curl than Net::HTTP or open-uri. But this poses a security risk. What's the best way to check the URL string and prevent any injection attacks?
I'm thinking of just using a regular expression like this to check for an injection attack:
raise...
Is Time.zone.now.to_date equivalent to Date.today?
Another way to put it: will Time.zone.now.to_date == Date.today always be true?
If not, what's the best way to get a Date object corresponding to "now" in the application time zone?
...
Ferret the ruby implementation of lucene is reasonably powerful, however online discussions in 2008 seemed to indicate ferret had many stability issues and would segfault regularly. There have been 10 or so commits this year so the project has pretty light activity.
Is Ferret stable enough to use in production?
...
The following hpricot code successfully extracts the STPeriods in the XML on two of my machines (Vista and an Ubuntu server) but fails on another Ubuntu laptop. All machines have Hpricot v0.82
Any ideas? Totally stumped.
Hpricot code:
(doc/"WeatherFeed/Location/WxShortTerm/STPeriod").each do |ham_forecast|
XML file
<?xml version=...
I'm running Ruby on Windows though I don't know if that should make a difference. All I want to do is get the current working directory's absolute path. Is this possible from irb? Apparently from a script it's possible using File.expand_path(FILE)
But from irb I tried the following and got a "Permission denied" error:
File.new(Dir.n...
David Korn, a proponent of the Unix philosophy, chided Perl programmers a few years ago in a Slashdot interview for writing monolithic Perl scripts without making use of the Unix toolkit through pipes, redirection, etc. "Unix is not just an operating system," he said, "it is a way of doing things, and the shell plays a key role by provid...
I'm trying to work with the data in my Rails application from within a separate Ruby script.
I read this forum post in which some people suggest that the best way to work with your data is to encapsulate the database within one application, and then have this application provide an API for working with that data. Because it's apparently...
I have three tables:
Posts
Keywordings
Keywords
Relevant fields in parens.
A Post
has_many :keywordings
has_many :keywords, :through => :keywordings
A Keywording(post_id, keyword_id)
belongs_to :post
belongs_to :keyword
A Keyword(name)
has_many :keywordings
has_many :posts, :through => :keywordings
I want to find all posts t...
Gibberish library provides a nice CBC algo...
// In Jascascript
GibberishAES.enc("Made with Gibberish\n", "password");
// Outputs: "U2FsdGVkX1+21O5RB08bavFTq7Yq/gChmXrO3f00tvJaT55A5pPvqw0zFVnHSW1o"
# On the command line
echo "U2FsdGVkX1+21O5RB08bavFTq7Yq/gChmXrO3f00tvJaT55A5pPvqw0zFVnHSW1o" |
openssl enc -d -aes-256-cbc -a -k passw...