Functional code examples in ruby
Hi, I'm looking for examples of functional code in ruby. Maybe you know some gems, where I can find such a code? ...
Hi, I'm looking for examples of functional code in ruby. Maybe you know some gems, where I can find such a code? ...
When posting from the has_calendar plugin, there is a request for the TranslationData. I'm not sure what this is, or how to set it (or where to set it). Here's the error it's spitting out. translation missing: en, date, formats, day_of_week Is there somewhere I need to set the locale for the calendar? The plugin doesn't give any inst...
Hey I just wanna know what is pythons equivalent of Ruby's each_slice(count) Like I wanna take 2 elements from list for each iteration. Like for [1,2,3,4,5,6] i wanna handle 1,2 in first iteration then 3,4 then 5,6. Ofcourse there is a roundabout way using index values. But is there a direct function or someway to do this directly? T...
I am working on a code base that has many modules nested 4 or 5 deep. Right now, this results in our code being heavily indented from the beginning. Is there an acceptable way of putting multiple module declarations on the same line? For example, module A module B #do stuff end end Is there a way to make it something like t...
I have the following data Animals = Dog Cat Turtle \ Mouse Parrot \ Snake I would like the regex to construct a match of just the animals with none of the backslashes: Dog Cat Turtle Mouse Parrot Snake I've got a regex, but need some help finishing it off. /ANIMALS\s*=\s*([^\\\n]*)/ ...
I'm working on a ruby on rails app that generates a large XML document using a builder template, but I've hit a bit of a stumbling point. The XML output must have a field that contains the file size in bytes. I think that I'll basically need to use the value that would populate the "Content-Length" header in the http response, but updat...
I'd like to slurp the following data about historical inventions into a convenient Ruby data structure: http://yootles.com/outbox/inventions.xml Note that all the data is in the XML attributes. It seems like there should be a quick solution with a couple lines of code. With Rails there'd be Hash.from_xml though I'm not sure that would...
Possible Duplicate: Model Using Modules in Rails Application I have a User model that is getting really fat and I want to break it up into submodules that correspond to the different interactions such as a user's interaction with friendships, interaction with events, interaction with weapons, etc. etc. What's the best way to g...
Hey guys, I'm going through the ruby koans, I'm on 151 and I just hit a brick wall. Here is the koan: # You need to write the triangle method in the file 'triangle.rb' require 'triangle.rb' class AboutTriangleProject2 < EdgeCase::Koan # The first assignment did not talk about how to handle errors. # Let's handle that part now. d...
I have such a case: class Person #a class that wraps to some db table def initialize(attributes=nil) populate_with_attributes(attributes) if !attributes.nil? end def self.find(id) @the_db.execute('query here where id....') end def save #save logic and queries here @the_db.execute('save query here') end # ...
I have built a form that submits values to Wufoo as a GET request in the URL. I cannot get it to work if any of the values (in a textarea) contain a line-break or a forward slash. Is there a way to encode these in a URL?? This is being done in Rails. Many thanks in advance, Galen ...
It seems this doesn't work as expected: if c = Countries.first.nil? ... do something end The comparison works but the assignment doesn't. Is there a way to do both the comparison and assignment in one line? ...
Suppose I have a string like "abc | xyz" and I'd like to turn it into "xyz | abc" using only a regular expression substitution. (For this example there may be better ways, but this is a stand-in for something hairier.) The following code doesn't do what I expect: x = "abc | xyz" x = x.gsub(/^([^\|\s]*)\s*\|\s*(\S*)/, "\2 | \1") puts x...
I am using the csv-mapper gem to import a csv file. When I use the example code on in the README (http://github.com/pillowfactory/csv-mapper) in script/console it works great. However, when I create a web form and use that to upload a csv file I get the error "No such file or directory - test.csv These are the parameters: Parameters: {...
I am generating some methods on the fly. The method body varies based on a certain criteria. I was relying on class_eval to generate conditional code. %Q{ def #{name} #{ (name != "password") ? "attributes[:#{name}]" : "encrypt(attributes[:#{name}])" } end } Recently I have started using define_...
I'm looking at the install.rb file of RoR open source project: version = ARGV.pop %w( core api auth dash promotions sample ).each do |framework| puts "Installing #{framework}..." `cd #{framework} && gem build spree_#{framework}.gemspec && gem install spree_#{framework}-#{version}.gem --no-ri --no-rdoc && rm spree_#{framework}-#{ver...
OK, real quick, here's the code: class A def foo FOO end def self.foo FOO end end module B class C < A end end B.const_set(:FOO,'asdf') >> B::C.foo NameError: uninitialized constant A::FOO from ./foo.rb:6:in `foo' from (irb):1 >> B.module_eval {FOO='asdf'} => "asdf" >> B::C.foo => "asdf" Aren't they suppos...
I have a starting page of http://www.example.com/startpage which has 1220 listings broken up by pagination in the standard way eg 20 results per page. I have code working that parses the first page of results and follows links that contain "example_guide/paris_shops" in their url. I then use Nokogiri to pull specific data of that final ...
(Sorry for long post) Ok guys, so I'm having some issues with something I'm trying, I've been trying to fix it for a long time now, and It's now time to ask for help. Ok, so I have these "grinders", and I want a user to vote for each one, I did two scaffolds: grinder grinder:string posted_timestamp:datetime poster_ip:string votes_up...
i have a web that provide a form to send SMS deployed on other server and a desktop application that is on my local machine serving as gateway. i wants when some user fill the form and submit it, then this sms delivered to desktop app to serve the request instantly. currently my local machine is interacting with the server after 30s then...