On 22/11/2016, Die Optimisten <inform / die-optimisten.net> wrote:
> Hi Robert!
>
>> This typically involves Ruby's command line options -e and -n or -p. A few
>> ways
>> ...
> Thank you!
>
>> 'unless /../;$_=nil end'
> So you can leave out the then ? ok, but I'ld prefer to have fixed syntax in
> a language
> (sometimes do or begin (not interchangeable), some ends without begin... -
> thats confusing)
>

If you prefer 'then', use 'then'. That's the beauty of not having a
prescribed/restrictive/'fixed' syntax.

';' ends the expression the same way and end-of-line would.

'do' is for closure-type blocks, 'begin' is for 'rescue'.

'end' closes any code block, no matter if it begins with 'if',
'begin', 'do', 'unless', 'while', etc. Of those, do-end is the only
one that can be replaced with braces. All the branching/looping
statements can also be used as post-conditionals ('x if y' or 'z until
a', etc.)

There is a lot of power and expressibility in Ruby's syntax.

>
> Another question:
> Is there a better way than eval to convert "number" data to its contents?
> x="3"	=> .to_i y=3
> x="3.3" => y=3.3
> x="0xa" => ? # y=16
> like printf with auto-detection of thze type
>

No. The auto-detection of type essentially means parsing the string as
ruby code, which is eval. It would be nice if there was a literal-only
mode for eval, which didn't invoke any method calls. That's a lot more
complicated than it sounds, though.

Cheers
-- 
  Matthew Kerwin
  http://matthew.kerwin.net.au/

Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>