similar to: Object and Classes ?

Displaying 20 results from an estimated 10000 matches similar to: "Object and Classes ?"

2006 Feb 15
2
extending rails via /lib - problems
I wanted to group some functions which I use in some models in one place. Controllers have application.rb and views have helpers but I couldn''t find anything about models. Using the /lib directory seemed to be the only way. Alright... so I have something like this: /lib/code.rb class ActiveRecord::Base def method_a(n) ....... end def method_b(n) ........ end end
2006 Jul 12
1
When to use Mutex::synchronize?
I have a simple question when to the synchronize method in the Mutex class. Now that backgroundrb has allow_concurrency = true there is no need to synchronize database calls in threads. The question I have is lets say I have a simple method in my worker as follows: def some_method SomeModel.find_all each do |obj| obj.some_count += 1 obj.save! end end It accesses the database, but
2006 Feb 18
5
Model methods and partial view templates
I have a method in a controller that invokes a render :partial => ''some_partial_view'' In that view, I''m trying to access a method defined in a model, like this; <% for view in @an_array %> <% local_var = view.some_method() %> <% another_var = view.a_column_name %> etc.. I am getting an undefined method error but the model is accessible
2006 Feb 16
10
Ruby class variables and access from view templates
I have an app that requires me to define a class variable (actually an array) in a controller and then access it from within a view. It seems that the class variables aren''t working right. Here is an example of what I''m trying to do. class DisplayController < ApplicationController @@thumbnail_array = Array.new ... def some_method @@thumbnail_array = SomeModel.find_all
2007 Mar 19
24
alias method spec?
I am completely baffled by this one - My guess is that there is no pure ruby way to do this - but how could I set up a spec to test that one method is an alias of another? Thanks for any help, Scott
2006 Jul 25
3
Question about how Mongrel process works with singletons
Hi, I have a controller where I access a singleton class that I use to connect to a DRbprocess DrbConnector.instance.some_method I notice that on every request, the constructor is called so it is making a new instance of this singleton. Is this normal? Thanks, Curtis
2006 Jul 14
3
Accessing the Model class from Controller
Hi, I wonder if there''s an easy way to access the associated Model class from its Controller. Something that would allow me to write snippets like the following: class PeopleController < ApplicationController def some_method person_model_class = self.some_method_to_retrieve_the_person_model_class() end end Cheers, Marco -- Posted via
2007 Sep 18
2
Making attachment_fu polymorphic
I am working on a small model mixin called attachment_kung to make attachment_fu polymorphic, so you no longer need a different table and Model class for every associated attachment (Productimage, Ad_doc, etc). All you really need is one model and table to handel all your attachments - in some cases, anyway. I have the code working, but have run into one small hitch that I can''t seem to
2012 Sep 04
5
Associations and Math between Models
I''ve setup two models, 1 and 2, that are associated by has_and_belongs_to_many. I''m trying to get an attribute from model_1 to use in a method in model_2. When I use the code below, I get an error saying ''undefined method model_1_id''. What am I missing? Thanks! Model_2.rb Class Model_2 < ActiveRecord::Base ... has_and_belongs_to_many :model_1 def
2007 Jul 25
2
initalizing and checking validity of S4 classes
Dear useRs and wizaRds, I am currently developing a set of functions using S4 classes. On the way I encountered the problem exemplified with the code below. For some reason the 'validity' method does not seem to work, i.e. does not check for errors in the specification of the slots of the defined class. Any hints? My understanding of the whole S4 system was that validity checks are made
2010 Apr 21
1
VERY basic question about S4 classes
Hi,   I'm new to R and S4 classes. I defined a class with two methods (myMethod1 and myMethod2). I want to call myMethod1 within myMethod2. Why does the code below not work? The name 'myMethod1' doesn't appear to have meaning inside myMethod2, even though the two methods belong to the same class.     setClass(Class="SomeClass",      representation=representation(      
2006 Jul 19
1
Passing objects to drb, does it keep the existing db connection?
I have a simple question. Let''s say I do this in one of my models: after_save drb_conn.some_method(self) end When that object gets over to the background process is it the exact same as?.... Model.find some_id #in the background process As far as my background process is concerned passing the object is not any different than passing the id and using the find method? Because
2006 Jan 20
1
Best way to execute timed actions?
I''ve seen this come up a few times before on this list but never felt it got a satisfactory answer. What is the best way to execute timed actions? Examples include sending an email each week, calculating interest each day, or cleaning up your database or server files. This wiki page has some ideas, but these seem a bit extreme.
2007 Jul 24
2
Dealing with nested/namespaced classes w/ describe
Hi all, Just wondering about this: I''ve been dealing with classes/modules nested in several layers of namespaces. Here would be an example of a describe block: describe ClassOne::ClassTwo::ClassThree, "description here" do ... end What would be the easiest way to write something a little more terse, like: describe ClassThree, "description here" do ... end
2016 Mar 03
2
as.vector in R-devel loaded 3/3/2016
I just installed R-devel to check my package before submitting. I got an error in my vignette in regards to as.vector. When I looked at the code for as.vector in R-devel it is standardGeneric for "as.vector" defined from package "base" function (x, mode) standardGeneric("as.vector") <environment: 0x0918ad70> Methods may be defined for arguments: x, mode Use
2013 Jul 09
5
whenever gem
Hello All, I want to schedule a mail every day. I used whenever gem. I added gem ''whenever'' in my gemfile. Then in the terminal I did - "whenever ." which created a schedule.rb. In schedule.rd I added this piece of code:- set :environment, "development" every 2.minutes do runner "UserMailer.some_method" end Does it get invoked
2012 Jul 05
1
Ruby DSL parameterized classes and defaults
I''ve been reading the Docs on this, and its not very clear. I want to have a parameterized class that takes arrays and objects as parameters. I''m using puppet 2.6.16. I define a hostclass like this: hostclass :test, :arguments => { :param1 => "blah" } do end I call from Puppet DSL: class {"test": } I get this as an error: err: Could not
2009 Apr 21
1
line wrap in R console under windows
I would like the R console to wrap lines at 80 cols. It does not do so, even though I have used the Rgui Configuration Editor to set the Console cols at 80 and the Pager cols at 80. Please tell me how to set it up so I have word wrap. Just to be clear: in older/other R versions, console input is wrapped at 80 cols and so you have something that looks like > blah blah blah blah blah blah blah
2011 Aug 25
2
replicate lines of data frame
Greetings! I am just now learning to use R for my dissertation project. I need to manipulate a lot of text and numeric data. I created a data frame that has 7 columns and 127 unique rows. Now I need to replicate each line 6 times and then later change values in the first 2 columns. I am trying to figure out how to accomplish this. I think that I need to use rep(my.df, each=6) but it does
2006 Mar 04
2
convert string to AR class
Hi everyone, I''m trying to convert a string passed on the command-line into an ActiveRecord class, so I can do something like this. a="SomeClass" a.find(:all) where class SomeClass < ActiveRecord::Base end This appears to work (better ways would be appreciated): a="SomeClass" b=eval a b.find(:all) However I would like to make sure