Slide 1

Slide 1 text

monkey_patching.in(:ruby) @huynhquancam

Slide 2

Slide 2 text

before(:talk) { about(:me) } Huỳnh Quán Cẩm. bug creator @ dadadee.com. die-hard Chelsea supporter. @huynhquancam | [email protected]

Slide 3

Slide 3 text

[:monkey, :patching].sample 3.gigabytes + 1.megabyte 2.seconds.ago 'John Doe'.should have_content('John')

Slide 4

Slide 4 text

what.is?(:monkey_patching) The dynamic modifications of a class or module at runtime. * A common pattern shared across Ruby community.

Slide 5

Slide 5 text

ruby.class.is(:open)

Slide 6

Slide 6 text

the (:good) -> { side } extremely convenient, especially for hot-fix. shorter code writing. nicer DSL syntax.

Slide 7

Slide 7 text

The “beauty” of monkey-patching

Slide 8

Slide 8 text

But it’s just simply not worth it!

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

the -> (dark) { side } global namespace pollution. codes are more difficult to debug and understand. poor upgradeability. race condition of libraries. …

Slide 12

Slide 12 text

– lotusrb “zero monkey-patch of Ruby core and stdlib.”

Slide 13

Slide 13 text

but there are certain times that patching becomes unavoidable

Slide 14

Slide 14 text

when(monkey.patch).makes_sense the original libraries got a bug. stubbing a method for testing. …

Slide 15

Slide 15 text

MP.without { making.a(mess) } Fork the library on Github.

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

MP.without { making.a(mess) } Fork the library on Github. Put them into a module.

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

MP.without { making.a(mess) } Fork the library on Github. Put them into a module. Standardise the way of your monkey-patching files structure.

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

MP.without { making.a(mess) } Fork the library on Github. Put them into a module. Keep them together. Use Ruby refinements.

Slide 22

Slide 22 text

ruby 2.x and above

Slide 23

Slide 23 text

“Ruby is a beautiful language, don’t ruin it.”

Slide 24

Slide 24 text

THANK YOU!

Slide 25

Slide 25 text

questions.any?