タグ

関連タグで絞り込む (0)

  • 関連タグはありません

タグの絞り込みを解除

devとRubyに関するtomo_ariのブックマーク (3)

  • Rubyで今実行中のメソッド名を知る - 2nd life (移転しました)

    http://www.lostway.org/~tko/cgi-bin/bakagaiku.rb?bakaid=200510131 を見て、exception起こしてbacktractで無理矢理取得、って方法を知る。アタマイイ!ということでObjectに組み込んでみた。ひょっとしたら使う機会があるかも? class Object def current_method begin raise StandardError rescue StandardError => e e.backtrace[1].scan(/`(.*)'/).to_s end end end で、下記のような挙動に。 def foo p current_method end foo #=> 'foo' 追記 id:ha-tan:20051014:1129218253 によると、callerを使えば例外を投げなくともbac

    Rubyで今実行中のメソッド名を知る - 2nd life (移転しました)
  • Why use Ruby's attr_accessor, attr_reader and attr_writer?

    You may use the different accessors to communicate your intent to someone reading your code, and make it easier to write classes which will work correctly no matter how their public API is called. class Person attr_accessor :age ... end Here, I can see that I may both read and write the age. class Person attr_reader :age ... end Here, I can see that I may only read the age. Imagine that it is set

    Why use Ruby's attr_accessor, attr_reader and attr_writer?
  • PHP しか書けなかった僕が Ruby を始めたころに思ったこと10点 « blog.udzura.jp

    RubyKaigi とか色々あって、ふと、僕がプログラミングを始めたころのことを何となく思い出したので走り書きしておきます。特に PHP に関しては記憶が曖昧なところがおおいので、 PHPer モヒカン族によるツッコミを歓迎します。 配列とハッシュが違う PHP においては、配列も連想配列もすべて array() と言う関数で生成する。むしろ、配列というものがキーを数字にしているだけの連想配列と言う位置づけだと思う。 Ruby ではもちろん、主たるコレクションには Array と Hash の二種類が存在し、区別される。最初はこの区別に若干戸惑いを覚えた。 ちなみに Python だとリスト・タプル・辞書ともっと増えるわけで、Javaのコレクションクラスに至ってはさらに多いし、この辺はどの実装が正しいとか適切とかではなく慣習なのかなあ、と思ったりする。 型(クラス)がより厳格 PHP では

  • 1