Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #6643

Re: Ruby newbie newline question

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.ruby
Subject Re: Ruby newbie newline question
Date 2012-10-09 18:58 +0200
Message-ID <adj3dmFbralU1@mid.individual.net> (permalink)
References <k4v5ee$o1l$1@dont-email.me> <adgs97Fqn4fU1@mid.individual.net> <k4vi9a$api$1@dont-email.me>

Show all headers | View raw


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
=> #<UnboundMethod: Class(Module)#attr_reader>
irb(main):002:0> class Foo; method :attr_reader; end
=> #<Method: Class(Module)#attr_reader>

Kind regards

	robert

Back to comp.lang.ruby | Previous | NextPrevious in thread | Find similar


Thread

Ruby newbie newline question Gary McGath <garym@REMOVEmcgathREMOVE.com> - 2012-10-08 14:18 -0400
  Re: Ruby newbie newline question Robert Klemme <shortcutter@googlemail.com> - 2012-10-08 22:44 +0200
    Re: Ruby newbie newline question Gary McGath <garym@REMOVEmcgathREMOVE.com> - 2012-10-08 17:57 -0400
      Re: Ruby newbie newline question Robert Klemme <shortcutter@googlemail.com> - 2012-10-09 18:58 +0200

csiph-web