If I''m not mistaken I''ve read once about ruby''s flexibility in letting you do something your own way (there is always more than 1 way to do something and ruby lets you choose your own way). And yes, syntax in ruby is flexible. But there is a way to write ruby code in c# style? writing 1.upto( 2 ) { | i | puts i.to_s } throws error. you have to write 1.upto( 2 ){ | i | # just one line here puts i.to_s } to work It seems here isn''t your way. it''s just ruby way... Or is there way I dont know to write c#-like code: function/instruction begin sign -{- ... block''s code ... end sign -}- -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 10, 2006, at 12:32 PM, George wrote:> > If I''m not mistaken I''ve read once about ruby''s flexibility in letting > you do something your own way (there is always more than 1 way to do > something and ruby lets you choose your own way). > And yes, syntax in ruby is flexible. But there is a way to write ruby > code in c# style? > writing > 1.upto( 2 ) > { | i | > puts i.to_s > } > throws error. > > you have to write > 1.upto( 2 ){ | i | # just one line here > puts i.to_s > } > to work > It seems here isn''t your way. it''s just ruby way... > Or is there way I dont know to write c#-like code: > function/instruction > begin sign -{- > ... block''s code ... > end sign -}-For short blocks, I believe it''s idiomatic to do: 1.upto(2) { |i| puts i.to_s } This also works but isn''t idiomatic because it puts the ''|i|'' on its own line: 1.upto(2) { |i| puts i.to_s } For longer blocks, it''s idiomatic to use do...end: 1.upto(2) do |i| puts i.to_s # more work here... # and here... # and so on... end However, if you don''t provide the opening ''{'' or ''do'' on the same line as the 1.upto(2), you''ll get an error that no block was given. I verified this in IRB (interactive Ruby) on Mac OS X w/ Ruby 1.8.5 from MacPorts. Regards, Craig --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
thanks for the reply i thought maybe there a way to tell ruby interpreter the new line in fact is not meant to be taken as a new line and that it''s just for code layout 1.upto( 3 )[a sign for ''hey, ruby, it''s a dummy new line here''] { | i | puts i } Just like there is a sign (--> ; <--) to tell ruby there should be a new line 1.upto( 3 ){ | i | print ''current: ''; puts i } the code above works fine because there is a --> ; <--; otherwise we get an error Craig Demyanovich wrote:> On Dec 10, 2006, at 12:32 PM, George wrote:-- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, Dec 10, 2006 at 07:30:03PM +0100, George wrote: } } thanks for the reply } } i thought maybe there a way to tell ruby interpreter the new line in } fact is not meant to be taken as a new line and that it''s just for code } layout } } 1.upto( 3 )[a sign for ''hey, ruby, it''s a dummy new line here''] } { | i | } puts i } } [...] 1.upto( 3 ) \ { | i | puts i } --Greg --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
thank you \ :) Greg and because there are so many ways to write ruby, is there a obfuscator to make the code more easy to be executed by ruby interpreter (that, let''s say, will transform the code from the most readible for you form to the easiest interpretable form for ruby) (or is it a practice in ruby world to obfuscate code before moving in production, and if yes, is there a significant performance gain)? Gregory Seidman wrote:> On Sun, Dec 10, 2006 at 07:30:03PM +0100, George wrote: > } > } thanks for the reply > } > } i thought maybe there a way to tell ruby interpreter the new line in > } fact is not meant to be taken as a new line and that it''s just for > code > } layout > } > } 1.upto( 3 )[a sign for ''hey, ruby, it''s a dummy new line here''] > } { | i | > } puts i > } } > [...] > > 1.upto( 3 ) \ > { | i | > puts i > } > > --Greg-- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---