Euruko 2017 Notes
Vừa rồi mình đi Euruko 2017 ở Budapest, một số bài nói cũng khá thú vị nên mình sẽ note lại ở đây.
Monkey-patching has been widely considered as bad practice in software development, in terms of source code management and maintainability.
Anyway, I believe everything has its own reason to exist, and below are something might change your mind about Monkey Patching.
Tired of keep typing something like User.find_by_username('jack')
in Rails console? Use this.
Monkey patch your object class in .irbrc
#!/usr/bin/ruby
require 'irb/completion'
require 'irb/ext/save-history'
class Object
def find_me
self.find_by_username '[email protected]'
end
end
Then now User.find_me
will return your favourite test user.
Tired of keep typing this?
users = User.all
p users.to_sql
users = users.order(username: :desc)
p users.to_sql
Then this might save your time.
class Object
def show_me(method)
tap { |obj| puts obj.send(method) }
end
end
# then now
User.all.show_me(:to_sql).order(username: :desc).show_me(:to_a)
Convinced yet? Leave your thoughts below!
Vừa rồi mình đi Euruko 2017 ở Budapest, một số bài nói cũng khá thú vị nên mình sẽ note lại ở đây.
A few days ago I encountered a strange behavior of Bundler so this post notes down how my experience with it was.
It’s undeniable that Rails is a great framework to speedily build up your application. However, despite of its handiness, like other frameworks, Rails has its own flaws and is never a silver bullet. This post is going to show you some of the gotchas (or pitfalls you name it) I encountered while working with Rails.