読者です 読者をやめる 読者になる 読者になる

valid,invalid

関心を持てる事柄について

8/2学んだこと / Ruby@codecademy / 英語

2015夏 英語 Ruby

Ruby

codecademy のRuby講座を90%まで進めた。今日カバーしたところは経験した言語にない、または似てるけど異なる要素があって面白かった。

  • Zen of Ruby

    There's always more than one way to do something in Ruby.

    Java, Pythonとは違う精神。Perlでは馴染みづらかったけど、Rubyはいまのところそうでもない。

  • Block

    These are similar to anonymous functions in JavaScript or lambdas in Python.

    A method can take a block as a parameter.

  • Hash

    What happens if you try to access a key that doesn't exist, though? In many languages, you'll get an error of some kind. Not so in Ruby: you'll instead get the special value nil.

  • Symbol

    Symbols make good hash keys for a few reasons:

    They're immutable, meaning they can't be changed once they're created;

    Only one copy of any symbol exists at a given time, so they save memory;

    Symbol-as-keys are faster than strings-as-keys because of the above two reasons.

    けっこう大事ぽい。

    hash lookup is faster with symbol keys than with string keys.

  • Conditional Assignment

    Java書いててよくムカつくことがクリアされててよい。(Optional型が入ってからもあんまりスマートにはなってない気がする)

  • Implicit Return

    ここはPythonとは完全に思想が違う。

    Explicit is better than implicit. PEP 20 -- The Zen of Python | Python.org

  • Yield

    Pythonのyieldと違って戸惑う。

    goo.gl

  • Proc

    You can think of a proc as a "saved" block: just like you can give a bit of code a name and turn it into a method, you can name a block and turn it into a proc.

  • The Ruby Lambda

    Like procs, lambdas are objects. The similarities don't stop there: with the exception of a bit of syntax and a few behavioral quirks, lambdas are identical to procs.

    Procとlambda何が違うんや〜と思ったら説明あった。

    If you're thinking that procs and lambdas look super similar, that's because they are! There are only two main differences.

    First, a lambda checks the number of arguments passed to it, while a proc does not. This means that a lambda will throw an error if you pass it the wrong number of arguments, whereas a proc will ignore unexpected arguments and assign nil to any that are missing.

    Second, when a lambda returns, it passes control back to the calling method; when a proc returns, it does so immediately, without going back to the calling method.

  • Class

    When dealing with classes, you can have variables that are available everywhere (global variables), ones that are only available certain methods (local variables), others that are members of a certain class (class variables), and variables that are only available to particular instances of a class (instance variables).

# instance variables
@name
# class variables
@@name
# global variables
$name # or define it outside of any method or class

残りはObject-Oriented Programmingのパートを少し。

英語

codecademy読んでただけ。たまに音読してみたけど結構詰まる。