In HAML I have hundreds of lines like the following: - xyz = someFuncThatReturnsString(''xyz'') and elsewhere %div{''id'' => xyz} The above lines work fine. - - - Attempting to keep things DRY (Don''t repeat yourself) I want to do something like - eval(otherFuncThatReturnsString(''xyz'')) where otherFuncThatReturnsString(''xyz'') returns "xyz = someFuncThatReturnsString(''xyz'')" When I do this, HAML no longer sees xyz as being defined when it attempts to interpret %div{''id'' => xyz} What am I doing wrong???? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Dec 21, 2010 at 3:05 PM, Ralph Shnelvar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> In HAML I have hundreds of lines like the following: > > - xyz = someFuncThatReturnsString(''xyz'') > > and elsewhere > > %div{''id'' => xyz} > > The above lines work fine. > > - - - > > Attempting to keep things DRY (Don''t repeat yourself) I want to do > something like > > - eval(otherFuncThatReturnsString(''xyz'')) > > where > > otherFuncThatReturnsString(''xyz'') > > returns > > "xyz = someFuncThatReturnsString(''xyz'')" > > When I do this, HAML no longer sees xyz as being defined when it > attempts to interpret > > %div{''id'' => xyz} > > What am I doing wrong????Defining variables on the views. You should define those variables in the controllers and then have them in the views or partials passing them as locals if necessary. -- Leonardo Mateo. There''s no place like ~ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ralph Shnelvar wrote in post #969835:> In HAML I have hundreds of lines like the following: > > - xyz = someFuncThatReturnsString(''xyz'') > > and elsewhere > > %div{''id'' => xyz} > > The above lines work fine. > > - - - > > Attempting to keep things DRY (Don''t repeat yourself) I want to do > something like > > - eval(otherFuncThatReturnsString(''xyz'')) > > where > > otherFuncThatReturnsString(''xyz'') > > returns > > "xyz = someFuncThatReturnsString(''xyz'')" > > When I do this, HAML no longer sees xyz as being defined when it > attempts to interpret > > %div{''id'' => xyz} > > What am I doing wrong????Almost everything. You''re using eval (almost never necessary in Ruby -- send is usually what you want). You''re using eval in the view (breaking MVC). You''re using dynamic element IDs (questionable but sometimes necessary). You''re using camelCase (poor style for Ruby). And most importantly, you''re asking a question that is so abstract that it has little to do with your actual goal. So...what are you actually trying to achieve here? What''s your *actual* code like? What errors or unexpected behavior are you getting? Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Dec 21, 2010 at 10:05 AM, Ralph Shnelvar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> In HAML I have hundreds of lines like the following: > > - xyz = someFuncThatReturnsString(''xyz'') > > and elsewhere > > %div{''id'' => xyz} > > The above lines work fine. >it will help if you can post a ''gist'' https://gist.github.com -- make haste slowly \ festina lente \ - mobile +1_415_632_6001 curtis-DDU1nqEjlGkHaT8GDLgCUg@public.gmane.org http://robotarmyma.de -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser wrote in post #969841:> You''re using eval (almost never necessary in Ruby -- > send is usually what you want).How in Ruby does one create a variable and then set a value for it without using eval? That is, I have a string named "xyz" and I want to create a variable named xyz and assign the string "abc" to it. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ralph Shnelvar wrote in post #970469:> Marnen Laibow-Koser wrote in post #969841: >> You''re using eval (almost never necessary in Ruby -- >> send is usually what you want). > > How in Ruby does one create a variable and then set a value for it > without using eval?There are several methods to do just that. But I don''t think that''s actually what you want here.> > That is, I have a string named "xyz" and I want to create a variable > named xyz and assign the string "abc" to it.As I said in my earlier post, I think you''re approaching this wrong. Please give more information about what you''re actually trying to achieve (rather than the surrogate goal you''ve set for yourself) and we''ll see what we can come up with. (You probably don''t need those variables in the first place.) Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.