quattro_4 scribble

scribble 落書き (調べた事をただ落書きする)

Starting RubyTapas #001 - #005

I have subscribed RailsCasts over 3 years.

I have subscribed Ruby5 over 2 years.

But I feel I'm not good at clean coding and programming design.

(Actually I realize myself improved to use many tools, gems etc for recent years.)

I started to subscribe RubyTapas.

001 Binary Literals

fileutilsを使うとき、2進数とか8進数で権限(chmod)を指定する話

002 Large Integer Literals

数値がアンダースコア( _ )で区切れる話

内容少なっ

003 Character Literals

★★

1文字の場合は ? を付けると .to_s になる

知らなかった。星2つ。

有料なので全内容を公開しないように気をつけないといけない

case文、getc、y/n で使うとCoolらしい

> ?y
=> "y"

大文字、記号、数値OK

> ?Y
=> "Y"
> ??
=> "?"
> ?_
=> "_"
> ?1
=> "1"

2文字だめ

> ?yy
SyntaxError: (irb):8: syntax error, unexpected '?'

Ruby 1.8

> ?y
=> 121

Ruby 1.9

> 'y'.ord
=> 121

ord, chrとかきりがないので止める

ascii - What's the opposite of chr() in Ruby? - Stack Overflow

もっとやる気か経験があったら、Rubyのソースを見ても良いかと思うが今はやらない

004 Barewords

全体としてはスコープとか変数とかの話

結局はbarewordsは推奨されないという話

だめな例

puts "#{HOGE}, #{title} #{first_name} #{last_name}. ",
     "Welcome to #{$progname} version #{DisOrganizer::VERSION}. ",
     "My name is #{@designation}

全部できるかぎりmethodにした方が良い

グローバル変数とか使った事無いけど思い出した $variable

salutation【名】〔手紙・演説などの最初の〕挨拶(の文句[言葉])

http://eow.alc.co.jp/salutation/utf-8/

005 Array Literals

★★

コマンドの引数を使うには %W がおすすめ

%W はinterpolateする %wはしない

options = %W[-f x11grab -s #{width}x#{height}]
system "command", *options

interpolate 挿入する、差し挟む -> 式展開

http://eow.alc.co.jp/search?q=interpolate

RubyTapasは発見当初はものすごくhackyで微妙だと思ってたけどそうでもなかった

今ぐらいのボリューム、難易度なら初期のRailsCastsのようにこなしていけそうな気もする