If I add this to the beginning of my script:
$KCODE = 'UTF8'
require 'jcode'
then I can walk over every char of a word containing unicode characters. Imagine a word containing umlauts or something, and I iterate over them like this:
word.each_char do |c|
# do something with c
end
If c is a unicode character and I print it's size,...
I'm writing some code that at run time may create or delete directories within the project path. I haven't really used ruby for file processing so i'm really uneasy about having code that, with a few mistypes weeks down the line, could result in wiping other directories outside of my project path.
Is there anyway to make it impossible ...
If a gem has rails dependencies, do you think it is better to write the gem tests in a way they can be run standalone or run them under a rails project?
...
I'm finding that with Ruby or RoR code, Netbeans' "go to declaration" doesn't show as lit up. Is there some way to turn this on?
Also: Eclipse with RadRails seems to have this for Ruby? RubyMine seems to as well... surely Netbeans can't be missing this normalish feature.
...
I have a rails app that loads lots of data from some java services. I'm writing a module that will allow me to populate some select boxes with this data and I'm trying to include these properly so I can reference them in my views. Here's my module
module FilterOptions
module Select
def some_select
return "some information"...
I would love to give my windows based desktop applications a web interface and vice versa. My desktop application is written in wxRuby and the webserver is Sinatra (using webrick). The simplest idea was just to mash them together, this does not work.
This code does not work. The webserver and gui app do not run simultaneously. The...
Hello,
If I have a class instance, containing several included modules, can I dynamically un-include a specific module (In order to replace it)?
Thanks.
...
Suppose you're in your users controller and you want to get a json response for a show request, it'd be nice if you could create a file in your views/users/ dir, named show.json and after your users#show action is completed, it renders the file.
Currently you need to do something along the lines of:
def show
@user = User.find( params...
I'm running the following method and I'm successfully passing two arguments (inventory, quantity) into the method. However I'm incorrectly using .first and .each methods. I'm attempting to replace .each with the .select to select for the cart item with the Inventory id: 6
possible .each replacement: (does not function) inventory_to_incr...
I'm trying to get this Sinatra GET request to work:
get '/:year/:month/:day/:slug' do
end
I know you can get one param to work with block parameters:
get '/:param' do |param|
"Here it is: #{param}."
end
But how can I use multiple block parameters with the first code block? I'm open to other methods.
...
I was passed a long running legacy ruby program, which has numerous occurances of
begin
#dosomething
rescue Exception => e
#halt the exception's progress
end
throughout it.
Without tracking down every single possible exception these each could be handling (at least not immediately), I'd still like to be able to shut it down at ...
Before I post this as a bug to the rails team, I wanted to see if I'm doing something wrong that may be causing this behavior. Specifically, the :autosave property of has_many associations doesn't seem to be working as per the docs.
For reference, here is the most current API documentation:
http://api.rubyonrails.org/classes/Acti … ati...
Came across this handy regular expression utility in Python (I am a beginner in Python). e.g. By using the regexp
(?P<id>[a-zA-Z_]\w*)
I can refer to the matched data as
m.group('id')
(Full documentation: look for "symbolic group name" here)
In Ruby, we can access the matched references using $1, $2 or using the MatchData object...
After upgrading to ruby 1.9 we began to notice pages failing to render from the rails template renderer when a user used a non-ASCII character. Specifically "é". I was able to resolve this issue on one of our staging servers, but I have not been able to reproduce the fix on our production server.
The fix that seemed to work the first ti...
In a gemspec file, is there a way to add dependency gem that hosts on other sites like github? I build a gem that has a dependency to http://github.com/mbleigh/mash. I checked the method add_dependency, but it seems it doesn't have that functionality. Could anyone show me how to do this?
...
Are there any applications out there that will let me encode my Ruby on Rails code so others can't read it? I plan on selling a few small applications, but I really don't want everyone knowing my code.
Thanks.
...
Hi,
I'd like to change dynamically the output used by the Logger.
in the lib:
@log = Logger.new(p, 10, 1024000)
in the main class:
mylib_instance.log.set_log(STDOUT) # something like that, but this does not work
Mickael.
...
I need to search all the *.c source files in the path to find a reference to a *.h header to find unused C headers. I wrote a ruby script but it feel very clumsy.
I create an array with all C files and an array with all the H files.
I iterate over the header file array. For each header I open each C file and look for a reference to the ...
I would like to allow users to write comments on a site. If they are registered users their username is displayed with the comment, otherwise allow them to type in a name which is displayed instead.
I was going to create a default anonymous user in the database and link every non-registered comment to that user. Would there be a bette...
Is it possible to use a case statement to replace these if statements?
if (a%3 == 0) then puts "%3"
elsif (a%4 == 0) then puts "%4"
elsif (a%7 == 0 && a%13 == 0) then puts "%%"
...