Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Loading...
Markdown vs. MongoDB A Journey through bleeding edge          technologies        for the NeXT Web
RubyMotion vs. Backbone A Journey through bleeding edge          technologies        for the NeXT Web
Rails Views     for theOO-savvy Rubyist
M        V    C
VC
Look at: Rails current implementation
def show @post = Post.find(params[:id]) @title = @post.titleend
<h1><%= @post.title %></h1><p><%= @post.body %></p>
<html> <head><title><%= @title %></title></head> <body><%= yield %></body></html>
And tell me boy, what‘s wrong                    with my @ivarsMy name‘s Guybrush threepwood.     I‘m new in townMatz told...
So how shouldI use @ivars?
When you design a class, you decidewhat internal state it has and alsodecide how that state is to appear onthe outside (to...
The internal state is held in instancevariables. The external state isexposed through methods we‘re call-ing attributes.
Dave Thomas,Programming Ruby
Deep in the Rails source...
# Define some internal variables that# should not be propagated to the view.self.protected_instance_variables = [  :@_stat...
# Define some internal variables that# should not be propagated to the view.self.protected_instance_variables = [  :@_stat...
protected instance variables
protected - instance - variables
And tell me boy, what ya                 doing about this?I‘ll stick with "helper_method".Give me some "decent_exposure"?I...
helper_methodpros: rails standardcons: verbose, bad semantics,class level
helper_methodpros: rails standardcons: verbose, bad semantics,class level
helper_methodpros: rails standardcons: verbose, bad semantics,class level
decent_exposurepros: easy syntax, good defaultscons: class level
decent_exposurepros: easy syntax, good defaultscons: class level
decent_exposurepros: easy syntax, good defaultscons: class level
obviewspros: easy syntax, action levelcons: unpublished
obviewspros: easy syntax, action levelcons: unpublished
obviewspros: easy syntax, action levelcons: unpublished!
We want examples!
We want examples!class PostsController < ApplicationController expose :posts def posts; Post.all; endend
We want examples!def show expose postenddef post; posts.find(params[:id]) end
We want examples!def show expose post: posts.find(params[:id])end
We want examples!<h1><%= pos title %></h1>           t.<p><%= post.body %></p>
Obviews
Obviewson rubygems shipping today!
Thank you !1
twitter:   @eliagithub:    @eliablog:      dev.mikamai.comblog:      elia.schito.me                     MIKAMAI No monkeys...
twitter:   @eliagithub:    @eliablog:      dev.mikamai.comblog:      elia.schito.me                     MIKAMAI No monkeys...
Rails OO views
Rails OO views
Rails OO views
Upcoming SlideShare
Loading in …5
×

Rails OO views

11,600 views

Published on

Published in: Technology, Education

Rails OO views

  1. 1. Loading...
  2. 2. Markdown vs. MongoDB A Journey through bleeding edge technologies for the NeXT Web
  3. 3. RubyMotion vs. Backbone A Journey through bleeding edge technologies for the NeXT Web
  4. 4. Rails Views for theOO-savvy Rubyist
  5. 5. M V C
  6. 6. VC
  7. 7. Look at: Rails current implementation
  8. 8. def show @post = Post.find(params[:id]) @title = @post.titleend
  9. 9. <h1><%= @post.title %></h1><p><%= @post.body %></p>
  10. 10. <html> <head><title><%= @title %></title></head> <body><%= yield %></body></html>
  11. 11. And tell me boy, what‘s wrong with my @ivarsMy name‘s Guybrush threepwood. I‘m new in townMatz told me their only for Object‘s internal stateWho‘s in charge here?Nice talking to you.
  12. 12. So how shouldI use @ivars?
  13. 13. When you design a class, you decidewhat internal state it has and alsodecide how that state is to appear onthe outside (to users of your class).
  14. 14. The internal state is held in instancevariables. The external state isexposed through methods we‘re call-ing attributes.
  15. 15. Dave Thomas,Programming Ruby
  16. 16. Deep in the Rails source...
  17. 17. # Define some internal variables that# should not be propagated to the view.self.protected_instance_variables = [ :@_status, :@_headers, :@_params, :@_env, :@_response, :@_request, :@_view_runtime, :@_stream, :@_url_options, :@_action_has_layout]
  18. 18. # Define some internal variables that# should not be propagated to the view.self.protected_instance_variables = [ :@_status, :@_headers, :@_params, :@_env, :@_response, :@_request, :@_view_runtime, :@_stream, :@_url_options, :@_action_has_layout]
  19. 19. protected instance variables
  20. 20. protected - instance - variables
  21. 21. And tell me boy, what ya doing about this?I‘ll stick with "helper_method".Give me some "decent_exposure"?It‘s "obviews"!I‘m made of rubber, you‘re made of glue.
  22. 22. helper_methodpros: rails standardcons: verbose, bad semantics,class level
  23. 23. helper_methodpros: rails standardcons: verbose, bad semantics,class level
  24. 24. helper_methodpros: rails standardcons: verbose, bad semantics,class level
  25. 25. decent_exposurepros: easy syntax, good defaultscons: class level
  26. 26. decent_exposurepros: easy syntax, good defaultscons: class level
  27. 27. decent_exposurepros: easy syntax, good defaultscons: class level
  28. 28. obviewspros: easy syntax, action levelcons: unpublished
  29. 29. obviewspros: easy syntax, action levelcons: unpublished
  30. 30. obviewspros: easy syntax, action levelcons: unpublished!
  31. 31. We want examples!
  32. 32. We want examples!class PostsController < ApplicationController expose :posts def posts; Post.all; endend
  33. 33. We want examples!def show expose postenddef post; posts.find(params[:id]) end
  34. 34. We want examples!def show expose post: posts.find(params[:id])end
  35. 35. We want examples!<h1><%= pos title %></h1> t.<p><%= post.body %></p>
  36. 36. Obviews
  37. 37. Obviewson rubygems shipping today!
  38. 38. Thank you !1
  39. 39. twitter: @eliagithub: @eliablog: dev.mikamai.comblog: elia.schito.me MIKAMAI No monkeys were harmed during the making of this keynote
  40. 40. twitter: @eliagithub: @eliablog: dev.mikamai.comblog: elia.schito.me MIKAMAI No monkeys were harmed during the making of this keynote

×