プログラミング言語基礎勉強会 sponsored by @wantedly UIターン at 2016 June 11
ご存知かとは思いますが、これまで仕事場では皆様のツイートと呼ばれる140文字程度の投稿を読んで適切なタイムラインに仕分けしたり、ハッシュタグを見て検索結果に追加したりとなかなか骨が折れる作業をしていて、随分慣れてきたのですが、どうしても最近はじまった「60秒でツイートを届けるキャンペーン」で間に合わないことが多く、中にはUnicodeの合字を組み合わせた塩抜きポテトみたいなツイートも多く、一部、Ruby を使って自動化したりしてみたのですが、そろそろ体力の限界を感じていたところでした1。 そんな折、同僚が、「オレ、Scala を使ってるんだけど肩こりも治ったし、60秒キャンペーンも余裕だよー」って言ってるのを聞いて、そんなにいいなら、とちょっと使ってみることにしました。 新しい言語を覚える 実際のところ、仕事場ではかなり前から Scala で書かれたプロジェクトがありましたが、この公開され
I've missed the memo somewhere, and I hope you'll explain this to me. Why is the eigenclass of an object different from self.class? class Foo def initialize(symbol) eigenclass = class << self self end eigenclass.class_eval do attr_accessor symbol end end end My train of logic that equates the eigenclass with class.self is rather simple: class << self is a way of declaring class methods, rather tha
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages) This article possibly contains original research. Please improve it by verifying the claims made and adding inline citations. Statements consisting only of original research should be removed. (September 2013) (Learn how and when to remove this message) T
オブジェクト指向プログラミングにおいてメタクラスとは、インスタンスがクラスとなるクラスのことである。通常のクラスがそのインスタンスの振る舞いを定義するように、メタクラスはそのインスタンスであるクラスを、そして更にそのクラスのインスタンスの振る舞いを定義する。全てのオブジェクト指向プログラミング言語でメタクラスが利用できるわけではない。利用できるものの中でもクラスの振る舞いが定義できる範囲は様々である。各言語はそれぞれ独自のメタオブジェクトプロトコル(MOP)を備えている[1]。メタオブジェクトプロトコルとは、クラスそのものの挙動をもオブジェクト指向のルールで記述し、初期化やインスタンス化のルール、実行状態の管理などをカスタマイズする機構である。Smalltalk、Common Lispが代表的である。 class Car(object): __slots__ = ['make', 'mod
When you learn about objects, you usually learn that they can capture two kinds of data: instance and class. Instance variables are the most common case, the data varies with each instance of the object. Class variables, often referred to as static variables, are shared across all instances of a class. Every instance points to same value and any changes are seen by all. Class variables are much le
Posted by Peter J. Jones on September 15, 2008 If you learned object oriented programming from one of the more static languages such as C++ or Java, the dynamic nature of Ruby may seem magical and elusive. After running into the syntax dedicated to meta-programming you may have been left scratching your head or at least wondering what’s happening behind the scenes. Singleton classes, not to be con
Classes in Ruby are first-class objects—each is an instance of class Class. -- ruby-doc.orgMost classes are defined using the syntax of the following example. class Person ... end Defining classes this way is familiar to most developers. Ruby provides another syntax for defining classes using Class.new. The following example also defines the Person class. Person = Class.new do ... endClass.new(sup
RubyのObject.dupとObject.cloneの違いは、特異メソッドとfreezeをコピーするかどうかである。 Object.cloneの方がコピーされる情報が多いが、一般的な用途にはObject.dupで十分だ。 以下は検証コード。 obj1 = Object.new obj1.taint def obj1.singleton_method; end obj1.freeze obj2 = obj1.dup obj3 = obj1.clone p obj1.tainted? #=> true p obj1.respond_to?(:singleton_method) #=> true p obj1.frozen? #=> true p obj2.tainted? #=> true p obj2.respond_to?(:singleton_method) #=> false p
タイトル メタプログラミングRuby 著者 Paolo Perrotta (著), 角征典 (翻訳) 出版社 アスキー・メディアワークス Amazonで購入する Ruby が人気のあるプログラミング言語である理由のひとつに、強力なメタプログラミングがあると思います。Ruby の本当の力を知るのは、このメタプログラミングを理解したときだとも思います。 本書は、Ruby の内部動作をきちんと説明した上で、メタプログラミングの説明をしてくれます。とても丁寧な説明で、少しでもプログラミングの知識があれば理解できる文章になっています。 プログラミング能力を高めるひとつの方法に、良いソースコードを読むことというのがあります。Ruby で書かれたフレームワークやライブラリのソースコードを読むと、なんでこんな動作になるんだろう?という疑問や、どうしてこんな風に書けるのだろう?という疑問が湧いてきます。 本
何でModuleモジュールのプライベートメソッドが任意のクラスで見えるんだー、 って書いてたら 師匠からメールが来た module をmix-inするには include extend の2種類あります。 この違いを理解すれば、わかるかと。そうなのか。 なら理解してみよう! 状況のまとめ p Module.private_instance_methods■実行結果 [:included, :extended, :prepended, :method_added, :method_removed, :method_undefined, :initialize_copy, :attr, :attr_reader, :attr_writer, :attr_accessor, :initialize, :remove_const, :append_features, :extend_object,
extend(*modules) -> self[permalink][rdoc][edit] 引数で指定したモジュールのインスタンスメソッドを self の特異メソッドとして追加します。 Module#include は、クラス(のインスタンス)に機能を追加しますが、extend は、ある特定のオブジェクトだけにモジュールの機能を追加したいときに使用します。 引数に複数のモジュールを指定した場合、最後の引数から逆順に extend を行います。 [PARAM] modules: モジュールを任意個指定します(クラスは不可)。 [RETURN] self を返します。 module Foo def a 'ok Foo' end end module Bar def b 'ok Bar' end end obj = Object.new obj.extend Foo, Bar p obj.a
We covered Modules in The RubyMonk Primer: Modules chapter. You should finish that lesson if you haven't done so already. In this section we'll discuss the included method. It is a callback that Ruby invokes whenever the module is included into another module/class. An example should make this clear:
railsのコード読んでると結構目にするmodule ClassMethods。 名前から一応類推できるのでスルーしてたのですが、GWで時間もあったので調べてみました。 ## クラスメソッドの追加 クラスメソッドの追加にはいろいろ方法があります。 * **class定義内でselfを使ってクラスメソッドを定義する** クラス定義内ではselfがそのクラスになります。 なので、下記のようにクラスメソッドを定義できます。
メソッド定義 Rubyのオブジェクトはメッセージに反応する。つまりオブジェクトがメッセージを受けると、オブジェクトは対応するメソッドを見つけてその結果を返す。 Rubyではオブジェクト自身はメソッドを持っていない。だからオブジェクトは自身が属するクラスにアクセスして、対応するメソッドを得てその結果を返す。 つまりRubyのメソッドはクラスに定義される。 メソッド定義はdef文で行う。 class Person def name(arg) "My name is #{arg}" end end my = Person.new my.name "Charlie" # => "My name is Charlie" 特定のクラスで定義されたメソッドは、そのクラスから生成されるオブジェクトで使えるようになる。 RubyではすべてのクラスはClassクラスから生成されたオブジェクトである。だからCl
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く