This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "golang.org/x/tour/pic" | |
| func Pic(dx, dy int) [][]uint8 { | |
| z := make([][]uint8, dy) | |
| for i := range z { | |
| z[i] = make([]uint8, dx) | |
| for j := range z[i]{ | |
| z[i][j] = uint8(i^j+(i+j)/2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Post | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User | |
| has_many :departments | |
| def department_name | |
| departaments.join(",") | |
| end | |
| end | |
| def user_info(user) | |
| "Name: #{user.name}. Dept: #{user.department_name}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User | |
| delegate :name, to: :department, prefix: true, allow_nil: true | |
| # ... | |
| end | |
| def user_info(user) | |
| "Name: #{user.name}. Dept: #{user.department_name}" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def user_info(user) | |
| "Name: #{user.name}. Dept: #{user.departments.map(&:name).join(",")}" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def user_info(user) | |
| "Name: #{user.name}. Boss: #{user.department.try(:head).try(:name)}" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def user_info(user) | |
| "Name: #{user.name}. Dept: #{user.department.try(:name)}" | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PostDecorator | |
| attr_reader :post | |
| def initialize post | |
| @post = post | |
| end | |
| def is_recent? | |
| published_at > 2.days.ago | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - if @post_decorator.recent? | |
| = image_tag(@post_decorator.image) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PostDecorator | |
| attr_reader :post | |
| def initialize post | |
| @post = post | |
| end | |
| def recent? | |
| published_at > 2.days.ago | |
| end |