Thanks to our catering sponsor Xenon we'll be offering better food than our usual pizza. Sign up quickly, as there's only limited capacity for this event. Agenda 19:00 〜 19:30 Doors open Grab a drink and catch up with your fellow Rubyists. 19:30 〜 19:55 The Pragmatic Hanami Kazuki Baba Hanami is a modern web framework for Ruby. This presentation will cover the basics of Hanami, explain its philoso
Rails の ActiveRecord には値オブジェクト (Value Object) を便利に使うための composed_of というものがあるらしいのでメモっとく。 エンティティ (Entity) と値オブジェクト エンティティと値オブジェクトはドメイン駆動設計におけるモデルを表現する3パターンの要素のうちの2つだ。 エンティティ 本からエンティティの説明を引用しておこう。 多くのオブジェクトは、本質的に、その属性によってではなく、連続性と同一性 (identity) によって定義される。 例えば Person クラスがあり、その属性は firstname・lastname・age だとしよう。Person クラスの2つのインスタンスがあり、それらが同姓同名同年齢だったとしても、その属性が一致しているからといって同一の人であるとは言えない。なので Person クラスのインスタン
サーバサイドエンジニアの中村です。先日開催されたRubyKaigi2017に参加しました。 その中で最も興味深かったセッションである The Ruby Module Builder Pattern について自分なりの理解をまとめてみようと思います。 Moduleの問題 module内でdefine_methodを使ってメソッド定義を行ったmethodに対して、そのmoduleをextendしたclass内で該当のメソッドに対して super を呼び出すことができません。 module AdderDefiner def define_adder(*keys) define_method :+ do |other| self.class.new( *(keys.map { |key| send(key) + other.send(key) }) ) end end end class Line
RubyKaigi2017帰りの@mactkgです。これからちまちまとブログを書いていくと思いますが、よろしくお願いします。普段はRubyでRailsを書いています。 入社してから毎日Ruby(たまにiOSとSQL)を書いている日々ですが、使用しているgemのコードを眺める中でModuleの表現力に驚かされることが多々ありました。そんな中参加したRubyKaigi2017での個人的テーマは、Moduleだったのではないかと振り返って感じます(MatzのKeynoteも、Moduleの話でした)。 そんな中会場で聞いた「The Ruby Module Builder Pattern」というトークが面白かったのですが、最近使ったShrineという画像アップロードのgemの実装とつながり、ビビっと来ましたので記事にします。まずはModule Builder Patternから…。 Module
There’s an interesting pattern I’ve discovered recently in Ruby that is very powerful, yet apparently not widely known or appreciated.1 I call this pattern the Module Builder Pattern. I’ve used it heavily in designing Mobility, a pluggable translation framework I released a couple months ago, and it served me so well I thought I should share what I’ve learned. At its core, the Module Builder is an
『るびま』は、Ruby に関する技術記事はもちろんのこと、Rubyist へのインタビューやエッセイ、その他をお届けするウェブ雑誌です。 Rubyist Magazine について 『Rubyist Magazine』、略して『るびま』は、Rubyist の Rubyist による、Rubyist とそうでない人のためのウェブ雑誌です。 最新号 Rubyist Magazine 0064 号 バックナンバー Rubyist Magazine 0064 号 Rubyist Magazine 0063 号 Rubyist Magazine 0062 号 Kaigi on Rails 特集号 RubyKaigi Takeout 2020 特集号 Rubyist Magazine 0061 号 Rubyist Magazine 0060 号 RubyKaigi 2019 直前特集号 Rubyist
Stay Relevant and Grow Your Career in TechPremium ResultsPublish articles on SitePointDaily curated jobsLearning PathsDiscounts to dev toolsStart Free Trial7 Day Free Trial. Cancel Anytime. Key Takeaways The Adapter Design Pattern in Ruby allows for greater flexibility and easier addition of new methods by separating implementations into modules, rather than using conditional branching. The Adapte
記念すべき「Rails Tips」第1回は、Decorator と Presenter について書きます。 Rails で Decorator/Presenter というと draper や active_decorator などの実績のある有名な gem パッケージが存在していて、それらを導入すれば話は簡単なのですが、本稿ではあえて Rails 標準の機能を用いて Decorator/Presenter を実現する方法を説明します。「車輪の再発明!」と言わないでください。自分で作ってみることによって Ruby や Rails の知識が深まり、様々な応用が利くようになります。実際のところ、そんなに複雑なものではありません。 Decorator とは 「Decorator」はソフトウェアデザインパターンの1つで、継承(inheritance)に代わるクラスの拡張手段です。 具体例で説明しまし
Photo by Flickr: HerryLawford's Photostream DraperはRailsのプレゼンテーション層の役割を担うgemです。 この記事では、Draperを通し、プレゼンテーション層の必要性や使い方を説明します。 動作確認 Ruby 2.2.1 Rails 4.2.0 Draper 1.4.0 目次 0. プレゼンテーション層の必要性 1. Draperのインストール方法 2. Draperの簡単な使い方 3. デコレーターインスタンスの作成 3.1. 単独のオブジェクトのデコレーター 3.2. コレクションの個々のオブジェクトのデコレーター 3.3. コレクション自身のデコレーター 3.4. 関連するオブジェクトのデコレーター 4. デコレータークラスの作成 4.1. デコレーター内でヘルパーメソッドへのアクセス 4.2. デコレーター内でモデルオブジェク
Railsで、モデルの内容をビューに出すときにちょっと加工するみたいな時、そのコードはどこに書けばいいんだ問題。 デザインパターンの一つにDecoratorパターンというのがあって、これを適用させるのが良いらしい。この用途ではactive_decoratorと並んで人気のgem、draperの説明がとてもわかりやすかった。 draperのREADMEで挙げられているのは、Articleという記事のモデルがあり、これの公開状態を表示させる機能を実装するという例だ。これを読み、なぜヘルパーメソッドやモデルに直に実装するんじゃだめなの?という疑問に対する答えを意訳していく。 ヘルパーメソッドを作る場合 ヘルパーメソッドで書くと、こうなる。 # app/helpers/articles_helper.rb def publication_status(article) if article.pub
Draperって何?Draperは、Model/Controller/View/Helperと異なる第4のレイヤを提供するGemです。 この第4のレイヤは、海外では「Presenter」として分類されています。(正確にもう少し細かい分類があるらしいですが割愛♪) このレイヤを作るメリットは、 model/viewに余計なロジックを書かなくてすむ Helperのメソッドが使われている場所が不明という事態を防ぐ 日本ではPresenterレイヤでは、ActiveDecoratorというGemが有名です。ActiveDecoratorもほぼ同じことができます。 Draperの紹介Draperの説明ならRailsCastが一番わかり易かったです(説明は日本語に翻訳されています、動画は英語です)↓ #####286 Draper - RailsCasts 1年前の記事ですので、実際に動かしてみると少
06 September 2006 Decorator Pattern with Ruby in 8 lines The Decorator Pattern is a design pattern that enables you to dynamically wrap behaviour around an existing object at runtime. It is especially useful when an object can have many variables that can be combined in different ways, which in turn affect it’s behaviour. This small, simple implementation of the decorator pattern in Ruby sums up w
Our Services Think Big. For as long as we can remember, we’ve defied expectations and embraced the insurmountable, and we’re still just getting warmed up. So bring us the impossible, and let’s leave the simple to everyone else. You’ll find us out front polishing the corners of the bleeding edge. Learn more Large Scale Web & CMS Large Scale Web & CMS. As a Drupal partner with demonstrated success w
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く