Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed101.telia.com!starscream.dk.telia.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.ruby Subject: Re: Ruby newbie newline question Date: Tue, 09 Oct 2012 18:58:29 +0200 Lines: 47 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net +7fiIqg5Mvt31OrthQIbdQFibtPk0M/25uBrBGZi5Gp23IeW0= Cancel-Lock: sha1:MZXVByJkiEaJPf0d/bHCEsOaJSo= User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120912 Thunderbird/15.0.1 In-Reply-To: Xref: csiph.com comp.lang.ruby:6643 On 10/08/2012 11:57 PM, Gary McGath wrote: > On 10/8/12 4:44 PM, Robert Klemme wrote: > >> There's also ";" which can be used instead: >> >> $ ruby19 -ce 'if i == 1 then print "one" elsif i == 2 then print "two" end' >> Syntax OK >> $ ruby19 -ce 'if i == 1; print "one" elsif i == 2 then print "two" end' >> Syntax OK >> $ ruby19 -ce 'if i == 1 print "one" elsif i == 2 then print "two" end' >> -e:1: syntax error, unexpected tIDENTIFIER, expecting keyword_then or >> ';' or '\n' >> if i == 1 print "one" elsif i == 2 then print "two" end >> ^ >> -e:1: syntax error, unexpected keyword_elsif, expecting $end >> if i == 1 print "one" elsif i == 2 then print "two" end >> ^ > > I see. Semicolon is a statement terminator, rather than being an > assignment terminator as in C-family languages. Useful to know. > >> I'm afraid I do not have more advice here. But this was really never a >> big issue for me IIRC. Just code away and let the syntax check give >> your the feedback. :-) > > Making conservative assumptions rather than trying to pare the code to > the minimum number of characters also sounds like good advice (i.e., > Ruby is not Perl :). And that's good - definitively! > I've been using _Learning Ruby_ from O'Reilly, which is readable but not > nearly as precise as I'd like. Thanks for the input. Well, actually Ruby's syntax is quite flexible - maybe too flexible in some places. But it's great that you can omit brackets for methods arguments. That makes creating DSLs pretty easy. Actually some things which look like keywords are actually methods: irb(main):001:0> Class.instance_method :attr_reader => # irb(main):002:0> class Foo; method :attr_reader; end => # Kind regards robert