Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Meta Programming - Bangalore Ruby Users Group - July '18 meetup

Meta Programming - Bangalore Ruby Users Group - July '18 meetup

In this presentation I talk about a particular problem statement and how I solved it using meta programming.

Vedant Agarwala

July 28, 2018
Tweet

More Decks by Vedant Agarwala

Other Decks in Programming

Transcript

  1. 1.Many key-value pairs 2.Be easy to modify 3.Both single and

    multiple select 4.SQL query friendly 5.DB should be consistent with views
  2. 1.Many key-value pairs 2.Be easy to modify 3.Both single and

    multiple select 4.SQL query friendly 5.DB should be consistent with views TAGS
  3. 1.Many key-value pairs 2.Be easy to modify 3.Both single and

    multiple select 4.SQL query friendly 5.DB should be consistent with views THE SINGLE SOURCE OF TRUTH
  4. WHERE IS THE CODE? class Portfolio def gender # ...

    end def gender=(value) # ... end
  5. - Meta Programming A programming technique in which computer programs

    have the ability to treat programs as their data. ” “
  6. FROM DATA TO CODE I18n.t('single_select').each do |key, value| # ...

    end I18n.t('multiple_select').each do |key, value| # ... end
  7. define_method key do |arg = {}| # ... end define_method

    (key.to_s + '=').to_sym do |arg| # ... end FROM DATA TO CODE
  8. 1.Many key-value pairs 2.Be easy to modify 3.Both single and

    multiple select 4.SQL query friendly 5.DB should be consistent with views PROBLEM SOLVED
  9. — Rails Doctrine Ruby includes a lot of sharp knives

    in its drawer of features. Not by accident, but by design. ” “