资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Ruby模版方法

Ruby设计模式:

坚守“ 做人真诚 · 做事靠谱 · 口碑至上 · 高效敬业 ”的价值观,专业网站建设服务10余年为成都成都纱窗小微创业公司专业提供成都定制网页设计营销网站建设商城网站建设手机网站建设小程序网站建设网站改版,从内容策划、视觉设计、底层架构、网页布局、功能开发迭代于一体的高端网站建设服务。

模板方法:定义一个操作中的算法的骨架而将一些步骤的实现延迟到子类中 模板方法使得之类可以不改变算法的结构既可重定义该算法的某些特定步骤

  1. #%()用来定义单行字符串 --- 包含“ 并且有字符串插值 
  2. class Report 
  3.   def output; puts "#{report_start}#{report_body}#{report_end}"; end 
  4.   def report_body 
  5.     %(\nbody\n) 
  6.   end 
  7. end 
  8.  
  9. class HtmlReport < Report 
  10.   def report_start 
  11.     %() 
  12.   end 
  13.   def report_end 
  14.     %() 
  15.   end 
  16. end 
  17.  
  18. class TextReport < Report 
  19.   def report_start 
  20.     %(=start=) 
  21.   end 
  22.  
  23.   def report_end 
  24.     %(=end=) 
  25.   end 
  26. end 
  27.  
  28. TextReport.new.output 
  29. HtmlReport.new.output 

结果:

=start=

body

=end=

body

 









 


网页标题:Ruby模版方法
文章分享:http://cdkjz.cn/article/jsgieo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220