<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1352368109032127573</id><updated>2024-09-07T16:00:47.475-07:00</updated><category term="ruby"/><category term="database"/><category term="Tools"/><category term="JavaScript"/><category term="git"/><category term="postgres"/><category term="Active record"/><category term="active admin"/><category term="gems"/><category term="ruby on rails"/><category term="Deployment"/><category term="Heroku"/><category term="JQuery"/><category term="rails"/><category term="Ajax"/><category term="Rails Configurations"/><category term="Ruby on Rails Jobs"/><category term="ruby blocks"/><category term="ubuntu"/><category term="Action View"/><category term="Discussions"/><category term="Helper"/><category term="Open sources"/><category term="Rails News"/><category term="Softwares"/><category term="Unix commands"/><category term="YAML"/><category term="customisation"/><category term="framework"/><category term="migrations"/><category term="rails3"/><category term="rvm"/><category term="validations"/><category term="Abstraction"/><category term="Behaviour Driven Development"/><category term="Ecommerce"/><category term="Email Templating"/><category term="Encapsulation"/><category term="Inheritance"/><category term="Latest things in rails"/><category term="Mocha"/><category term="PMS"/><category term="Polymorphism"/><category term="ReactJS"/><category term="Rubymine"/><category term="Text Editor"/><category term="coding"/><category term="collect"/><category term="devise"/><category term="inject"/><category term="interview"/><category term="lambda"/><category term="layouts"/><category term="mongodb"/><category term="mysql"/><category term="oops"/><category term="payment gateways"/><category term="proc"/><category term="questions"/><category term="rails console"/><category term="rake"/><category term="reject"/><category term="rspec"/><category term="ruby 1.8"/><category term="ruby 1.9"/><category term="ruby on rails blogs"/><category term="select"/><category term="self"/><category term="servers"/><category term="sql"/><category term="ssh"/><category term="twitter bootstrap"/><title type='text'>rails-knowledge</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>122</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-4832727377216714666</id><published>2018-02-16T09:21:00.002-08:00</published><updated>2018-02-16T09:21:39.829-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ReactJS"/><title type='text'>React Ecosystem</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;b&gt;Composition Model :&lt;/b&gt; Everything is a component. we create composition functions inoder to build UI with components.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Declarative:&lt;/b&gt; Reduce side effects, Minimize Mutability, More readable code and less bugs.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Unidirectional Data Flow: &lt;/b&gt;Sate &amp;gt; UI (You manage the state, UI will automatically update on its own)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Explicit Mutation:&lt;/b&gt; this.setState we are explicitly update the state.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Just JavaScript:&amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/4832727377216714666/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2018/02/react-ecosystem.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/4832727377216714666'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/4832727377216714666'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2018/02/react-ecosystem.html' title='React Ecosystem'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-4956567936552349538</id><published>2016-06-09T00:22:00.002-07:00</published><updated>2016-06-09T00:22:37.442-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="Mocha"/><title type='text'>TypeError: (0 , _chai.expect)(...).toBe is not a function</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Error while running Mocha tests: &lt;br /&gt;
&lt;br /&gt;
TypeError: (0 , _chai.expect)(...).toBe is not a function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;By doing some research, came to see that I need to use a different syntax while using &#39;chai&#39;&lt;br /&gt;
&lt;br /&gt;
By changing my test cases as below got worked.&lt;br /&gt;
&lt;br /&gt;
expect(true).to.be.true;&lt;br /&gt;expect(false).to.be.false;&lt;br /&gt;
&lt;br /&gt;
Thank You,&lt;br /&gt;
Uma Mahesh.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/4956567936552349538/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2016/06/typeerror-0-chaiexpecttobe-is-not.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/4956567936552349538'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/4956567936552349538'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2016/06/typeerror-0-chaiexpecttobe-is-not.html' title='TypeError: (0 , _chai.expect)(...).toBe is not a function'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-1162370374078948272</id><published>2016-06-08T07:50:00.003-07:00</published><updated>2016-06-08T07:50:45.781-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>jsdom </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif, &#39;Apple Color Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;A JavaScript implementation of the DOM and HTML standards&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif, &#39;Apple Color Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;Install:&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;-webkit-text-stroke-width: 0px; background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #333333; font-family: Consolas, &#39;Liberation Mono&#39;, Menlo, Courier, monospace; font-size: 13.6px; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 1.45; margin-bottom: 0px; margin-top: 0px; orphans: auto; overflow: auto; padding: 16px; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-break: normal; word-spacing: 0px; word-wrap: normal;&quot;&gt;$ npm install jsdom&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif, &#39;Apple Color Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;&amp;nbsp;Its much more like DOM&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif, &#39;Apple Color Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif, &#39;Apple Color Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;its mainly used for testing&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif, &#39;Apple Color Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif, &#39;Apple Color Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;Its creates a virtual DOM.. there is no browser and no selenium scripts...&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif, &#39;Apple Color Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif, &#39;Apple Color Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif, &#39;Apple Color Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/tGlZpGIRnUY/0.jpg&quot; src=&quot;https://www.youtube.com/embed/tGlZpGIRnUY?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif, &#39;Apple Color Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif, &#39;Apple Color Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif, &#39;Apple Color Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;Thank You,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif, &#39;Apple Color Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;Uma Mahesh.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-family: &#39;Helvetica Neue&#39;, Helvetica, &#39;Segoe UI&#39;, Arial, freesans, sans-serif, &#39;Apple Color Emoji&#39;, &#39;Segoe UI Emoji&#39;, &#39;Segoe UI Symbol&#39;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/1162370374078948272/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2016/06/jsdom.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/1162370374078948272'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/1162370374078948272'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2016/06/jsdom.html' title='jsdom '/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/tGlZpGIRnUY/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-750016671982467697</id><published>2016-06-08T00:01:00.001-07:00</published><updated>2016-06-08T00:01:11.605-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="git"/><title type='text'>get latest code and rebase to local branch </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;gt; git branch&lt;br /&gt;
&lt;br /&gt;
&amp;gt; git checkout develop&lt;br /&gt;
&lt;br /&gt;
To fetch all remote branches.&lt;br /&gt;
&amp;gt; git fetch origin&lt;br /&gt;
&lt;br /&gt;
To rebase local develop branch with remote develop branch.&lt;br /&gt;
&amp;gt; git rebase origin/develop &lt;br /&gt;
&lt;br /&gt;
&amp;gt; git checkout &amp;lt;your branch&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to rebase local branch with develop branch &lt;br /&gt;
&amp;gt; git rebase develop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Thank You,&lt;br /&gt;
Uma Mahesh.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/750016671982467697/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2016/06/get-latest-code-and-rebase-to-local.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/750016671982467697'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/750016671982467697'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2016/06/get-latest-code-and-rebase-to-local.html' title='get latest code and rebase to local branch '/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-4112087058208294292</id><published>2016-06-07T23:17:00.001-07:00</published><updated>2016-06-07T23:17:12.461-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="git"/><title type='text'>command to delete remote branch from git</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Here is the command to delete branch from remote repo in git&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;gt; git push origin --delete &amp;lt;Branch name&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This will delete branch from local machine as well as remote repo.&lt;br /&gt;
&lt;br /&gt;
Thank You,&lt;br /&gt;
Uma Mahesh.&lt;br /&gt;
&amp;nbsp;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/4112087058208294292/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2016/06/command-to-delete-remote-branch-from-git.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/4112087058208294292'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/4112087058208294292'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2016/06/command-to-delete-remote-branch-from-git.html' title='command to delete remote branch from git'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-5649274695967429720</id><published>2016-02-15T03:34:00.001-08:00</published><updated>2016-02-15T03:34:31.575-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="git"/><title type='text'>Git push asking for username and password</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
When I try to push the code to github, I need to submit username and password every time. I keep on asking for username and password while pushing the code. &lt;br /&gt;&lt;br /&gt;I came to see its due to ssh. &lt;br /&gt;&lt;br /&gt;I have checked my remote config of my git repo and came to see it was with https&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;git remote –v&lt;br /&gt;Now I removed the remote repo which is with https as below&lt;br /&gt;&amp;gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;git remote rm origin&lt;br /&gt;&lt;br /&gt;Now I added the remote repo with git as below&lt;br /&gt;&amp;gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;git remote add origin git@github.com:umamahesh/sampleapp.git&lt;br /&gt;&lt;br /&gt;Now authentication happens without ssh and with keys. You can push the code without username and password. &lt;br /&gt;&lt;br /&gt;Thank You,&lt;br /&gt;Uma Mahesh.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/5649274695967429720/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2016/02/git-push-asking-for-username-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/5649274695967429720'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/5649274695967429720'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2016/02/git-push-asking-for-username-and.html' title='Git push asking for username and password'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-3020681925727065026</id><published>2016-02-15T03:20:00.000-08:00</published><updated>2016-02-15T03:20:04.352-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="git"/><title type='text'>get code from remote branch in git</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
When you want to pull the branch code from same&amp;nbsp; repo, first navigate to main branch. Main branch is the reference branch. &lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; git checkout master&lt;br /&gt;&lt;br /&gt;From the main branch checkout to ‘develop’ branch. Develop branch is the name of the remote branch I am referring to. &lt;br /&gt;&amp;gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;git checkout develop&lt;br /&gt;&amp;gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;git pull origin develop&lt;br /&gt;Now you will get the latest code from develop branch.&lt;br /&gt;&lt;br /&gt;Below are the steps to merge the code from your branch to develop branch.&lt;br /&gt;&lt;br /&gt;Let’s suppose you are working on the branch ‘uma-development’, Now you want to merge your code to ‘develop’ branch.&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;git checkout uma-development&lt;br /&gt;&amp;gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;git rebase develop&lt;br /&gt;&lt;br /&gt;you may see many conflicts while doing the rebase. Try to solve conflicts one by one… after solving the conflicts, do git add&lt;br /&gt;&amp;gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;git add.&lt;br /&gt;&amp;gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;git rebase –continue&lt;br /&gt;&lt;br /&gt;once your conflicts got resolved you are done with rebase. Now your branch ‘uma-development ‘ is up to date with develop branch code. &lt;br /&gt;&lt;br /&gt;Now push the code to develop branch in remote and then raise pull request to develop branch. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Thanks,&lt;br /&gt;
Uma Mahesh.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/3020681925727065026/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2016/02/get-code-from-remote-branch-in-git.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/3020681925727065026'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/3020681925727065026'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2016/02/get-code-from-remote-branch-in-git.html' title='get code from remote branch in git'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-6450380494837331189</id><published>2014-11-05T22:26:00.004-08:00</published><updated>2014-11-05T22:26:49.213-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="layouts"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="self"/><title type='text'>assign default layout in controller</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;Here is the method to check layout in the controller.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;You can &lt;span style=&quot;background-color: white; color: black; display: inline ! important; float: none; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 17.8048px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;debug the controller self object and check there is any layout name like this..&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;background-color: white; color: black; display: inline ! important; float: none; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 17.8048px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;self.action_has_layout?&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;background-color: white; color: black; display: inline ! important; float: none; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 17.8048px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;before_filter :check_and_assign_default_layout&lt;br /&gt;def check_and_assign_default_layout&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; unless self.action_has_layout?&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.action_has_layout = &quot;my_layout&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;background-color: white; color: black; display: inline ! important; float: none; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 17.8048px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;Thank You,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;background-color: white; color: black; display: inline ! important; float: none; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 17.8048px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;Uma Mahesh.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;background-color: white; color: black; display: inline ! important; float: none; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 17.8048px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/6450380494837331189/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2014/11/assign-default-layout-in-controller.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/6450380494837331189'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/6450380494837331189'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2014/11/assign-default-layout-in-controller.html' title='assign default layout in controller'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-1034821303336525797</id><published>2014-10-24T02:54:00.002-07:00</published><updated>2014-10-24T02:54:46.441-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="interview"/><category scheme="http://www.blogger.com/atom/ns#" term="questions"/><category scheme="http://www.blogger.com/atom/ns#" term="rails"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby"/><title type='text'>Ruby on Rails Interview Questions</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
Ruby Interview Questions&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby Interview Questions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. What is a class method and how you will define it?&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;Class methods are methods that are called on a class without creating instance of that class.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;# Way 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Way 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #Way3 &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;class Foo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; class Foo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; class Foo; end&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;def self.bar &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; class &amp;lt;&amp;lt; self &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; def Foo.bar&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;puts &#39;class method&#39; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; def bar &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; puts &#39;class method&#39;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;puts &#39;class method&#39; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end end end&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;Calling class method =&amp;gt; Foo.bar&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. What is an instance method and how you will instantiate it?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Instance methods are methods that are called on an instance of a class.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; # Way 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Way 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Way 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; class Foo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;class Foo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; class Foo; end&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;def baz &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;attr_accessor :baz &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;foo = Foo.new&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; puts &#39;instance method&#39; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;def foo.bar&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foo = Foo.new &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; puts &#39;instance method&#39;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foo.baz = &#39;instance method&#39; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Instantiating instance methods:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a). f = Foo.new&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;f.bar&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b). &amp;nbsp;g = Foo.new&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; g.send(:bar)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c). Foo.new.bar&lt;br /&gt;
&lt;br /&gt;
3. What is singleton class and singleton method ? (http://www.devalot.com/articles/2008/09/ruby-singleton)&lt;br /&gt;
&amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;A singleton method is a method that is defined only for a single object.&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;o = &quot;message&quot; &amp;nbsp; &amp;nbsp; &amp;nbsp;# A string is an object&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;def o.printme &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;# Define a singleton method for this object&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; puts self&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; o.printme &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;# Invoke the singleton&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;A method added to a single object rather than to a class of objects is known as a singleton method.&lt;br /&gt;
&amp;nbsp; &amp;nbsp;The implicit class object to which such singleton methods are added is sometimes called a singleton class or singel class instead.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4. What are the closures in ruby?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; In Ruby, procs and lambdas are closures . Closure refers to an object that is both an invocable function and a variable binding for that function.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; When you create a proc or a lambda, the resulting Proc &amp;nbsp;object holds not just the executable block but also bindings for all the variables used by the block.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. What is the difference between Proc and Lambda?&lt;br /&gt;
&lt;br /&gt;
http://railsknowledge.blogspot.in/2014/10/what-is-difference-between-proc-and.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. What is the difference between Ruby 1.8.7 and 1.9.2?&lt;br /&gt;
&lt;br /&gt;
http://railsknowledge.blogspot.in/2014/10/what-is-difference-between-ruby-187-and.html&lt;br /&gt;
&lt;br /&gt;
7. What is a module and what is the use of it?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Like a class, a module &amp;nbsp;is a named group of methods, constants, and class variables.&lt;br /&gt;
Modules are defined much like classes are, but the module &amp;nbsp;keyword is used in place of&lt;br /&gt;
the class &amp;nbsp;keyword. Unlike a class, however, a module cannot be instantiated, and it &amp;nbsp;cannot be subclassed. Modules stand alone; there is no “module hierarchy” of inheritance. Modules are used as namespaces and as mixins.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Namespaces:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Modules are a good way to group related methods when object-oriented programming&lt;br /&gt;
is not necessary.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Mixins:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; The second use of modules mixins. If a module defines instance methods instead of the class methods, those instance methods can be mixed in to other classes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. What is the difference between collect,select, reject and inject in ruby?&lt;br /&gt;
&lt;br /&gt;
http://railsknowledge.blogspot.in/2014/10/what-is-difference-between.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
9. What is Enumerator in ruby?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;An enumerator &amp;nbsp;is an Enumerable &amp;nbsp;object whose purpose is to enumerate some other object. To use enumerators in Ruby 1.8, you must require &#39;enumerator&#39; . In Ruby 1.9, enumerators are built-in and no require &amp;nbsp;is necessary.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
10.Difference between ‘load’ and ‘require’ in Ruby?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;The difference between load and require is that load includes the specified Ruby file every time the method is executed and require includes the Ruby file only once.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;• In addition to loading source code, require &amp;nbsp;can also load binary extensions to Ruby. Binary &amp;nbsp;extensions are, of course, implementation-dependent, but in C-based implementations, they typically take the form of shared library files with extensions like .so &amp;nbsp;or .dll .&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;• load &amp;nbsp;expects a complete filename including an extension. require &amp;nbsp;is usually passed a library name, with no extension, rather than a filename. In that case, it searches for a file that has the library name as its base name and an appropriate source or native library extension. If a directory contains both an .rb &amp;nbsp;source file and a binary extension file, require &amp;nbsp;will load the source file instead of the binary file.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;• load &amp;nbsp;can load the same file multiple times. require &amp;nbsp;tries to prevent multiple loads of the same file. (require &amp;nbsp;can be fooled, however, if you use two different, but equivalent, paths to the same library file. In Ruby 1.9, require &amp;nbsp;expands relative paths to absolute paths, which makes it somewhat harder to fool.) require &amp;nbsp;keeps track of the files that have been loaded by appending them to the global array&lt;br /&gt;
$&quot; &amp;nbsp;(also known as $LOADED_FEATURES ). load &amp;nbsp;does not do this.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; • load &amp;nbsp;loads the specified file at the current $SAFE &amp;nbsp;level. require &amp;nbsp;loads the specified library with $SAFE &amp;nbsp;set to 0 , even if the code that called require &amp;nbsp;has a higher value for that variable. See §10.5 for more on $SAFE &amp;nbsp;and Ruby’s security system. (Note that if $SAFE &amp;nbsp;is set to a value higher than 0 , require &amp;nbsp;will refuse to load any file with a tainted filename or from a world-writable directory. In theory, therefore, it should be safe for require &amp;nbsp;to load files with a reduced $SAFE &amp;nbsp;level.)&lt;br /&gt;
&lt;br /&gt;
11. What is string interpolation in Ruby?&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; We can embedded an expression in double coded string using curly brackets preceding with #. This is called string interpolation.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Name =”vijay” &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Puts “My name is #{name}”&lt;br /&gt;
&lt;br /&gt;
12. what is the difference between dup and clone methods in Ruby?&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; The Ruby built-in methods Object#clone and #dup produce copies of their receiver. They differ in the amount of context they copy. The dup method copies just the object&#39;s content, whereas clone also preserves things such as singleton classes associated with the object.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s1 = &quot;cat&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; def s1.upcase&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;CaT&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s1_dup &amp;nbsp; = s1.dup&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s1_clone = s1.clone&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;#=&amp;gt; &quot;cat&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s1_dup.upcase &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #=&amp;gt; &quot;CAT&quot; &amp;nbsp;(singleton method not copied)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s1_clone.upcase &amp;nbsp; &amp;nbsp; &amp;nbsp; #=&amp;gt; &quot;CaT&quot; &amp;nbsp;(uses singleton method)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
13. Difference between include and extend in Ruby?&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Include is for adding methods to an instance of a class and extend is for adding class methods&lt;br /&gt;
&lt;br /&gt;
module Foo&lt;br /&gt;
&amp;nbsp; def foo&lt;br /&gt;
&amp;nbsp; &amp;nbsp; puts &#39;heyyyyoooo!&#39;&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Bar&lt;br /&gt;
&amp;nbsp; include Foo&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Bar.new.foo # heyyyyoooo!&lt;br /&gt;
Bar.foo # NoMethodError: undefined method ‘foo’ for Bar:Class&lt;br /&gt;
&lt;br /&gt;
class Baz&lt;br /&gt;
&amp;nbsp; extend Foo&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Baz.foo # heyyyyoooo!&lt;br /&gt;
Baz.new.foo # NoMethodError: undefined method ‘foo’ for #&amp;lt;Baz:0x1e708&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, include makes the foo method available to an instance of a class and extend makes the foo method available to the class itself.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
14. Defining &amp;nbsp;attr_access &amp;nbsp;like methods in Ruby?&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;class Demo&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;def self.test_accessor (*args)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; args.each do |e|&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;define_method(e) do&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; puts instance_variable_get(&quot;@#{e}&quot;)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; define_method(&quot;#{e}=&quot;) do |val|&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;instance_variable_set(&quot;@#{e}&quot;,val)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;test_accessor :hello,:vijay&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
15. What is the output &amp;nbsp;of x=1/2 in ruby?&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 # zero&lt;br /&gt;
Division of one integer by another results in a truncated integer. This is a feature, not a bug. If you need a floating point number, make sure that at least one operand is a floating point.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
16. Write a method in Ruby to display given number of Fibonacci series?&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;def fibonacci(n)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a,b = 0,1&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; n.times do&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;%d\n&quot;, a)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a,b = b,a+b&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
17. Difference between String and Symbol in ruby?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Symbols are Strings, just with an important difference, Symbols are immutable. Mutable objects can be changed after assignment while immutable objects can only be overwritten.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; String: Strings are mutable, the Ruby interpreter never knows what that String may hold in terms of data. As such, every String needs to have its own place in memory.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Example:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; puts &quot;hello world&quot;.object_id &amp;nbsp; &amp;nbsp;# =&amp;gt; 3102960&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; puts &quot;hello world&quot;.object_id &amp;nbsp; # =&amp;gt; 3098410&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Symbol: Every Symbol shares the same object id, and as such the same space on the heap. To further increase performance, Ruby will not mark Symbols for destruction, allowing you to reuse them again and again. Symbols are not only stored in memory, they are also keep track of via an optimized Symbols dictionary.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Example:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; puts :&quot;hello world&quot;.object_id &amp;nbsp;# =&amp;gt; 239518&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; puts :&quot;hello world&quot;.object_id &amp;nbsp;# =&amp;gt; 239518&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
18. What is true, false and nil in ruby?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;true evaluates to an object that is a singleton instance of TrueClass. Likewise, false and nil are singleton instances of FalseClass and NilClass.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;Note that true, false, and nil refer to objects, not numbers. false and nil are not the same thing as 0, and true is not the same thing as 1. nil behaves like false, and any value other than nil or false behaves like true.&lt;br /&gt;
&lt;br /&gt;
19. Garbage collection in Ruby?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;ObjectSpace.garbage_collect, which forces Ruby’s garbage collector to run. Garbage collection functionality is also available through the GC module. GC.start is a synonym for ObjectSpace.garbage_collect. Garbage collection can be temporarily disabled with GC.disable, and it can be enabled again with GC.enable.&lt;br /&gt;
&lt;br /&gt;
20. Program to find given String is palindrome or not?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; def palindrome?(str)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; str.length &amp;lt;= 1 or (str[0,1] == str[-1,1] and palindrome?(str[1..-2]))&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; puts palindrome?(&quot;aja&quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;Without Recursion call:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;def palindrome?(string)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string == string.reverse&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end&lt;br /&gt;
&lt;br /&gt;
21. Difference between Array and Hash in Ruby?&lt;br /&gt;
&amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Arrays: Arrays are used to store collections of data. Each object in an array has an unique key assigned to it.&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; We can access any object in the array using this unique key.&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; The positions in an array starts from &quot; 0 &quot;. The first element is located at &quot; 0 &quot;, the second at 1st position etc.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A Hash is a collection of key-value pairs. It is similar to an Array, except that indexing is done via arbitrary keys of any object type,&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; not an integer index.&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; Hashes enumerate their values in the order that the corresponding keys were inserted.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;So we use arrays when the order matters&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;We use hashes when we want the convenience of refering to objects by their labels&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
22. Program to reverse the given line in Ruby?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; words = %w(Son I am able she said)&lt;br /&gt;
&amp;nbsp; str = &quot;&quot;&lt;br /&gt;
&amp;nbsp; words.reverse_each { |w| str += &quot;#{w} &quot;} &amp;nbsp; &amp;nbsp; # str is now &quot;said she able am I Son &quot;&lt;br /&gt;
&amp;nbsp;&lt;br /&gt;
&amp;nbsp;&lt;br /&gt;
23. Program to find given number is prime or not?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;def prime?(n)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;prime = false&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;factor = 1&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if n== 0 or n == 1&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; prime = false&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for i in 1..(n-1)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if n%i == 0&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;factor = i&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if factor &amp;gt; 1&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;prime = false&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;prime = true&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; return prime&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;end&lt;br /&gt;
&lt;br /&gt;
24. Program to find given number is palindrome or not ?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;def palindrome?(n)&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num = n&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; while n&amp;gt;0&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dig = n%10&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; reverse = reverse*10 + dig&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; n = n/10&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if num == reverse&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return true&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return false&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
25. Program to find given number is odd or even?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; def odd_even?(n)&lt;br /&gt;
&amp;nbsp; &amp;nbsp;if n%2 == 0&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; return true&lt;br /&gt;
&amp;nbsp; &amp;nbsp;else&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;return false&lt;br /&gt;
&amp;nbsp; &amp;nbsp;end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
26. Program to print reverse of the given string?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;def str_reverse str&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reverse = ‘ ‘&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;chars = str.each_char.to_a&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;chars.size.times { reverse &amp;lt;&amp;lt; chars.pop}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; puts reverse&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end&lt;br /&gt;
&lt;br /&gt;
27. How to instantiate a module self.method in a class?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;If you want to have both class methods and instance methods mixed into a class when including a module, you may follow the pattern:&lt;br /&gt;
&amp;nbsp;YourModule&lt;br /&gt;
&amp;nbsp; module ClassMethods&lt;br /&gt;
&amp;nbsp; &amp;nbsp; def a_class_method&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; puts &quot;I&#39;m a class method&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; end&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; def an_instance_method&lt;br /&gt;
&amp;nbsp; &amp;nbsp; puts &quot;I&#39;m an instance method&quot;&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; def self.included(base)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; base.extend ClassMethods&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Whatever&lt;br /&gt;
&amp;nbsp; include YourModule&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Whatever.a_class_method&lt;br /&gt;
# =&amp;gt; I&#39;m a class methodmodule&lt;br /&gt;
&lt;br /&gt;
Whatever.new.an_instance_method&lt;br /&gt;
# =&amp;gt; I&#39;m an instance method&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;28. Object-oriented programming in Ruby&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;http://railsknowledge.blogspot.in/2014/10/object-oriented-programming-in-ruby.html&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/1034821303336525797/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2014/10/ruby-on-rails-interview-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/1034821303336525797'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/1034821303336525797'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2014/10/ruby-on-rails-interview-questions.html' title='Ruby on Rails Interview Questions'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-2376416211732925064</id><published>2014-10-24T02:52:00.000-07:00</published><updated>2014-10-24T02:52:38.227-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Abstraction"/><category scheme="http://www.blogger.com/atom/ns#" term="Encapsulation"/><category scheme="http://www.blogger.com/atom/ns#" term="Inheritance"/><category scheme="http://www.blogger.com/atom/ns#" term="oops"/><category scheme="http://www.blogger.com/atom/ns#" term="Polymorphism"/><title type='text'>Object-oriented programming in Ruby</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 15px; line-height: 16.8666667938232px;&quot;&gt;&lt;b&gt;Object-oriented programming in Ruby&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;div&gt;
&lt;span style=&quot;font-family: Times New Roman, serif;&quot;&gt;&lt;span style=&quot;font-size: 15px; line-height: 16.8666667938232px;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;There are three widely used programming paradigms there.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Procedural programming&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Functional programming&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Object-oriented programming.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Ruby is an object-oriented language. It has some functional and procedural
features too.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Object-oriented
programming (OOP)&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt; is
a programming paradigm that uses objects and their interactions to design
applications and computer programs.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;There are some basic programming concepts in OOP:&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Abstraction&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;Polymorphism&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Encapsulation&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Inheritance&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The &lt;b&gt;abstraction&lt;/b&gt; is
simplifying complex reality by modeling classes appropriate to the problem.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The
&lt;b&gt;polymorphism&lt;/b&gt; is the process of using
an operator or function in different ways for different data input.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The &lt;b&gt;encapsulation&lt;/b&gt; hides the implementation
details of a class from other objects.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The &lt;b&gt;inheritance&lt;/b&gt;
is a way to form new classes using classes that have already been defined.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;h2 style=&quot;line-height: 115%; margin-bottom: 4.0pt; margin-left: 0in; margin-right: 0in; margin-top: .25in;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;, serif; font-size: 11pt; line-height: 115%;&quot;&gt;Objects&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/h2&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Objects are basic building blocks of a Ruby OOP program. An
object is a combination of data and methods. In a OOP program, we create
objects. These objects communicate together through methods.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Each object can
receive messages, send messages and process data.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;There are two steps in creating an object.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;First, we define a
class. A &lt;b&gt;class&lt;/b&gt; is a template for an
object. It is a blueprint, which describes the state and behavior that the
objects of the class all share.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;A class can be used to create many objects.
Objects created at runtime from a class are called &lt;b&gt;instances&lt;/b&gt; of that particular class.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;#!/usr/bin/ruby&lt;br /&gt;
class Being&amp;nbsp; &lt;br /&gt;
end&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;
b = Being.new&lt;br /&gt;
puts b&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;
In our first example, we create a simple object.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;class Being &lt;br /&gt;
end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;This is a simple class definition. The body of the template
is empty. It does not have any data or methods.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;b = Being.new&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We create a new instance of the Being class. For this we have
the new method. The b variable stores the newly created object.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;puts b&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We print the object to the console to get some basic
description of the object.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;What does it mean, to print an object? When we print
an object, we in fact call its to_s method. But we have not defined any method
yet. It is because every object created inherits from the base Object. It has
some elementary functionality, which is shared among all objects created. One
of this is the to_s method.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;$ ./simple.rb&lt;br /&gt;
#&amp;lt;Being:0x9f3c290&amp;gt;&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We get the object class name.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;h2 style=&quot;line-height: 115%; margin-bottom: 4.0pt; margin-left: 0in; margin-right: 0in; margin-top: .25in;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;, serif; font-size: 11pt; line-height: 115%;&quot;&gt;The constructor&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/h2&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;A constructor is a special kind of a method. It is
automatically called, when the object is created. Constructors do not return
values. The purpose of the constructor is to initiate the state of an object.
The constructor in Ruby is called initialize. Constructors do not return any
values.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Constructors cannot be inherited. The constructor of a parent
object is called with a super method. They are called in the order of
inheritance.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;#!/usr/bin/ruby&lt;br /&gt;
&lt;br /&gt;
class Being&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;Being is created&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Being.new&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We have a Being class.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The Being class has a constructor method called initialize.
It prints a message to the console. The definition of a Ruby method is placed
between the def and end keywords.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Being.new&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;An instance of the Being class is created. At the moment of
the object creation, the constructor method is called.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;$ ./constructor.rb&lt;br /&gt;
Being is created&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;This is the output of the program.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Object attributes is the data bundled in an instance of a
class. The object attributes are called &lt;b&gt;instance
variables&lt;/b&gt; or &lt;b&gt;member fields&lt;/b&gt;. An
instance variable is a variable defined in a class, for which each object in
the class has a separate copy.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In the next example, we initiate data members of the class.
Initiation of variables is a typical job for constructors.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;#!/usr/bin/ruby&lt;br /&gt;
&lt;br /&gt;
class Person&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def initialize name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @name = name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def get_name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p1 = Person.new &quot;Jane&quot;&lt;br /&gt;
p2 = Person.new &quot;Beky&quot;&lt;br /&gt;
&lt;br /&gt;
puts p1.get_name&lt;br /&gt;
puts p2.get_name&lt;br /&gt;
In the above Ruby code, we have a Person class with one member field.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;class Person&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def initialize name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @name = name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In the constructor of the Person class, we set a member field
to a value name. The name parameter is passed to the constructor at creation. A
constructor is a method called initialize that is being called at the creation
of an instance object. The @name is an instance variable. Instance variables
start with @ character in Ruby.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;def get_name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; @name&lt;br /&gt;
end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The get_name method returns the member field. In Ruby member
fields are accessible only via methods.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;p1 = Person.new &quot;Jane&quot;&lt;br /&gt;
p2 = Person.new &quot;Beky&quot;&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We create two objects of a Person class. A string parameter
is passed to each object constructor. The names are stored inside instance
variables that are unique to each object.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;puts p1.get_name&lt;br /&gt;
puts p2.get_name&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We print the member fields by calling the get_name on each of
the objects.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;$ ./person.rb&lt;br /&gt;
Jane&lt;br /&gt;
Beky&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We see the output of the program. Each instance of the Person
class has its own name member field.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We can create an object without calling the constructor. Ruby
has a special allocate method for this. The allocate method allocates space for
a new object of a class and does not call initialize on the new instance.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;#!/usr/bin/ruby&lt;br /&gt;
&lt;br /&gt;
class Being&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp; def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;Being created&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
b1 = Being.new&lt;br /&gt;
b2 = Being.allocate&lt;br /&gt;
puts b2&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In the example, we create two objects. The first object using
the new method, the second object using the allocate method.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;b1 = Being.new&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Here we create an instance of the object with the new
keyword. The constructor method initialize is called and the message is printed
to the console.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;b2 = Being.allocate&lt;br /&gt;
puts b2&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In case of the allocate method, the constructor is not
called. We call the to_s method with the puts keyword to show, that the object
was created.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;$ ./allocate.rb&lt;br /&gt;
Being created&lt;br /&gt;
#&amp;lt;Being:0x8ea0044&amp;gt;&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Output of the program.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;h2 style=&quot;line-height: 115%; margin-bottom: 4.0pt; margin-left: 0in; margin-right: 0in; margin-top: .25in;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;, serif; font-size: 11pt; line-height: 115%;&quot;&gt;Constructor overloading&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/h2&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Constructor overloading is the ability to have multiple types
of constructors in a class. This way we can create an object with different
number or different types of parameters.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Ruby &lt;b&gt;has no
constructor overloading&lt;/b&gt; that we know from other programming languages.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;This
behaviour can be simulated to some extent with default parameter values in
Ruby.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;#!/usr/bin/ruby&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class Person&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def initialize
name=&quot;unknown&quot;, age=0&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @name = name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @age = age&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def to_s&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;Name: #{@name}, Age:
#{@age}&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p1 = Person.new&lt;br /&gt;
p2 = Person.new &quot;unknown&quot;, 17&lt;br /&gt;
p3 = Person.new &quot;Becky&quot;, 19&lt;br /&gt;
p4 = Person.new &quot;Robert&quot;&lt;br /&gt;
&lt;br /&gt;
p p1, p2, p3, p4&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;This example shows how we could simulate constructor
overloading on a Person class that has two member fields. If we do not specify
the name of the person, we have &quot;unknown&quot; string instead. For
unspecified age we have 0.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;def initialize name=&quot;unknown&quot;, age=0&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; @name = name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; @age = age&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The constructor takes two parameters. They have a default
value. The default value is used, if we do not specify our own values at the
object creation. Note that the order of parameters must be kept. First comes
the name, then the age.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;p1 = Person.new&lt;br /&gt;
p2 = Person.new &quot;unknown&quot;, 17&lt;br /&gt;
p3 = Person.new &quot;Becky&quot;, 19&lt;br /&gt;
p4 = Person.new &quot;Robert&quot;&lt;br /&gt;
&lt;br /&gt;
p p1, p2, p3, p4&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We create four objects. The constructors take different
number of parameters.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;$ ./consover.rb&lt;br /&gt;
Name: unknown, Age: 0&lt;br /&gt;
Name: unknown, Age: 17&lt;br /&gt;
Name: Becky, Age: 19&lt;br /&gt;
Name: Robert, Age: 0&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Output of the example.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;h2 style=&quot;line-height: 115%; margin-bottom: 4.0pt; margin-left: 0in; margin-right: 0in; margin-top: .25in;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;, serif; font-size: 11pt; line-height: 115%;&quot;&gt;Methods&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/h2&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Methods are functions defined inside the body of a class.
They are used to perform operations with the attributes of our objects. Methods
are essential in &lt;b&gt;encapsulation&lt;/b&gt;
concept of the OOP paradigm. For example, we might have a connect method in our
AccessDatabase class. We need not to be informed, how exactly the method
connects to the database. We only have to know, that it is used to connect to a
database. This is essential in dividing responsibilities in programming.
Especially in large applications.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In Ruby, data is accessible only via methods.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;#!/usr/bin/ruby&lt;br /&gt;
&lt;br /&gt;
class Person&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def initialize name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @name = name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def get_name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
per = Person.new &quot;Jane&quot;&lt;br /&gt;
&lt;br /&gt;
puts per.get_name&lt;br /&gt;
puts per.send :get_name&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The example shows two basic ways to call a method.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;puts per.get_name&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The common way is to use a dot operator on an object followed
by a method name.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;puts per.send :get_name&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The alternative is to use a built-in send method. It takes a
symbol of the method to be called as a parameter.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Methods typically perform some action on the data of the
object.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;#!/usr/bin/ruby&lt;br /&gt;
&lt;br /&gt;
class Circle&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; @@PI = 3.141592&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @radius = 0&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def set_radius radius&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @radius = radius&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def area&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @radius * @radius * @@PI&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
c = Circle.new&lt;br /&gt;
c.set_radius 5&lt;br /&gt;
puts c.area&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In the code example, we have a Circle class. We define two
methods.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;@@PI = 3.141592&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We have defined a @@PI variable in our Circle class. It is a
class variable. Class variables start with @@ sigils in Ruby. Class variables
belong to a class, not to an object. Each object has access to its class
variables. We use the @@PI to compute the area of the circle.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; @radius = 0&lt;br /&gt;
end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We have one member field. It is the radius of the circle. If
we want to modify this variable from the outside, we must use the publicly
available set_radius method. The data is protected.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;def set_radius radius&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; @radius = radius&lt;br /&gt;
end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;This is the set_radius method. It gives the @radius instance
variable a new value.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;def area&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; @radius * @radius * @@PI&lt;br /&gt;
end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The area method returns the area of a circle. This is a
typical task for a method. It works with data and produces some value for us.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;c = Circle.new&lt;br /&gt;
c.set_radius 5&lt;br /&gt;
puts c.area&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We create an instance of the Circle class. And set its radius
by calling the set_radius method on the object of the circle. We use the dot
operator to call the method.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;$ ./circle.rb&lt;br /&gt;
78.5398&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Running the example.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;h2 style=&quot;line-height: 115%; margin-bottom: 4.0pt; margin-left: 0in; margin-right: 0in; margin-top: .25in;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;, serif; font-size: 11pt; line-height: 115%;&quot;&gt;Access modifiers&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/h2&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Access modifiers set the visibility of methods and member
fields. Ruby has three access modifiers:&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;public, protected and private.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In
Ruby, all data members are private. Access modifiers can be used only on
methods.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Ruby methods are public, unless we say otherwise.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The public methods can be accessed from inside the definition
of the class as well as from the outside of the class.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The difference between
the protected and the private methods is subtle.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;They both cannot be accessed
outside the definition of the class. They can be accessed only within the class
itself and by inherited or parent classes.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;Note that unlike in other object-oriented programming
languages, &lt;/span&gt;&lt;b style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;inheritance does not play
role&lt;/b&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt; in Ruby access modifiers.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;Only two things are important. First, if we
call the method inside or outside the class definition. Second, if we use or do
not use the self keyword which points to the current receiver.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Access modifiers protect data against accidental
modifications. They make the programs more robust. The implementation of some
methods is subject to change. These methods are good candidates for being
private. The interface that is made public to the users should only change when
really necessary. Over the years users are accustomed to using specific methods
and breaking backward compatibility is generally frowned upon.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;#!/usr/bin/ruby&lt;br /&gt;
&lt;br /&gt;
class Some&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def method1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;public method1
called&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def method2&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;public method2
called&quot;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def method3&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;public method3
called&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; method1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.method1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
s = Some.new&lt;br /&gt;
s.method1&lt;br /&gt;
s.method2&lt;br /&gt;
s.method3&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The example explains the usage of public Ruby methods.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;def method1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;public method1
called&quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The method1 is public, even if we did not specify the public
access modifier. It is because methods are public by default, if not specified
otherwise.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;public&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; def method2&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;public method2
called&quot;&amp;nbsp; &lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ...&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Methods following the public keyword are public.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;def method3&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;public method3 called&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; method1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.method1&lt;br /&gt;
end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;From inside the public method3, we call other public method.
With and without the self keyword.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;s = Some.new&lt;br /&gt;
s.method1&lt;br /&gt;
s.method2&lt;br /&gt;
s.method3&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Public methods are the only methods that can be called
outside the definition of a class as shown here.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;$ ./public_methods.rb&lt;br /&gt;
public method1 called&lt;br /&gt;
public method2 called&lt;br /&gt;
public method3 called&lt;br /&gt;
public method1 called&lt;br /&gt;
public method1 called&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Running the example.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The next example looks at private methods.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;#!/usr/bin/ruby&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class Some&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; method1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # self.method1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def method1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;private method1
called&quot;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
s = Some.new&lt;br /&gt;
# s.method1&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Private methods are tightest methods in Ruby. They can be
called only inside a class definition and without the self keyword.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; method1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # self.method1&lt;br /&gt;
end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In the constructor of the method, we call the private
method1. Calling the method with the self is commented. Private methods cannot
be specified with a receiver.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;private&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; def method1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;private method1
called&quot;&amp;nbsp; &lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Methods following the private keyword are private in Ruby.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;s = Some.new&lt;br /&gt;
# s.method1&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We create an instance of the Some class. Calling the method
outside the class definition is prohibited. If we uncomment the line, the Ruby
interpreter gives an error.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;$ ./private_methods.rb&lt;br /&gt;
private method called&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Output of the example code.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Finally, we will work with protected methods. The distinction
between the protected and the private methods in Ruby is subtle. Protected
methods are like private. There is only one small difference. They can be
called with the self keyword specified.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;#!/usr/bin/ruby&lt;br /&gt;
&lt;br /&gt;
class Some&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; method1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.method1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; protected&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def method1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;protected method1
called&quot;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
s = Some.new&lt;br /&gt;
# s.method1&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The above example shows protected method in usage.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; method1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.method1&lt;br /&gt;
end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Protected methods can be called with and without the self
keyword.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;protected&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; def method1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;protected method1
called&quot;&amp;nbsp; &lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Protected methods are preceded by the protected keyword.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;s = Some.new&lt;br /&gt;
# s.method1&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Protected methods cannot be called outside the class definition.
Uncommenting the line would lead to an error.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;h2 style=&quot;line-height: 115%; margin-bottom: 4.0pt; margin-left: 0in; margin-right: 0in; margin-top: .25in;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;, serif; font-size: 11pt; line-height: 115%;&quot;&gt;Inheritance&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/h2&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The inheritance is a way to form new classes using classes
that have already been defined. The newly formed classes are called &lt;b&gt;derived&lt;/b&gt; classes, the classes that we
derive from are called &lt;b&gt;base&lt;/b&gt; classes.
Important benefits of inheritance are code reuse and reduction of complexity of
a program. The derived classes (descendants) override or extend the
functionality of base classes (ancestors).&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;#!/usr/bin/ruby&lt;br /&gt;
&lt;br /&gt;
class Being&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;puts &quot;Being class created&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Human &amp;lt; Being&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; super&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;Human class
created&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Being.new&lt;br /&gt;
Human.new&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In this program, we have two classes. A base Being class and
a derived Human class. The derived class inherits from the base class.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;class Human &amp;lt; Being&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In Ruby, we use the &amp;lt; operator to create inheritance
relations. The Human class inherits from the Being class.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; super&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;Human class created&quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The super method calls the constructor of the parent class.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Being.new&lt;br /&gt;
Human.new&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We instantiate the Being and the Human class.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;$ ./inheritance.rb &lt;br /&gt;
Being class created&lt;br /&gt;
Being class created&lt;br /&gt;
Human class created&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;First the Being class is created. The derived Human class
also calls the costructor of its parent.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;An Object may be involved in comlicated relationships. A
single object can have multiple ancestors. Ruby has a method ancestors which
gives a list of ancestors for a specific class.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Each Ruby object is automatically a descendant of Object,
BasicObject classes and Kernel Module. They are built-in the core of the Ruby
language.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;#!/usr/bin/ruby&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class Being &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Living &amp;lt; Being &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Mammal &amp;lt; Living &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Human &amp;lt; Mammal &lt;br /&gt;
end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
p Human.ancestors&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We have four classes in this example. A Human is a Mammal a
Living and a Being.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;p Human.ancestors&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We print the ancestors of a Human class.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;$ ./ancestors.rb &lt;br /&gt;
[Human, Mammal, Living, Being, Object, Kernel, BasicObject]&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;A Human class has three custom and three built-in ancestors.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;A more complex example follows.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;#!/usr/bin/ruby&lt;br /&gt;
&lt;br /&gt;
class Being&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; @@count = 0&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @@count += 1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;Being class
created&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def show_count&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;There are #{@@count}
beings&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Human &amp;lt; Being&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; super&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;Human is created&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Animal &amp;lt; Being&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; super&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;Animal is created&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Dog &amp;lt; Animal&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; super&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;Dog is created&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Human.new&lt;br /&gt;
d = Dog.new&lt;br /&gt;
puts d.show_count&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We have four classes. The inheritance hierarchy is more
complicated. The Human and the Animal classes inherit from the Being class. And
the Dog class inherits directly from the Animal class and further from the
Being class. We also use a class variable to count the number of beings
created.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;@@count = 0&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We define a class variable. A class variable begins with @@
sigils and it belongs to the class, not to the instance of the class. We use it
to count the number of beins created.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; @@count += 1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;Being class created&quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Each time the Being class is instantiated, we increase the
@@count variable by one. This way we keep track of the number of instances
created.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;class Animal &amp;lt; Being&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
class Dog &amp;lt; Animal&lt;br /&gt;
...&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The Animal inherits from the Being and the Dog inherits from
the Animal. Further, the Dog inherits from the Being as well.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Human.new&lt;br /&gt;
d = Dog.new&lt;br /&gt;
puts d.show_count&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We create instances from the Human and from the Dog classes.
We call the show_count method on the Dog object. The Dog class has no such
method; the grandparent&#39;s (Being) method is called then.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;$ ./inheritance2.rb&lt;br /&gt;
Being class created&lt;br /&gt;
Human is created&lt;br /&gt;
Being class created&lt;br /&gt;
Animal is created&lt;br /&gt;
Dog is created&lt;br /&gt;
There are 2 beings&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The Human object calls two constructors. The Dog object calls
three constructors. There are two Beings instantiated.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Inheritance does not play role in the visibility of methods
and data members. This is a notable difference from many common object-oriented
programming languages.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In C# or Java, private data members and methods are not
inherited. Only public and protected. In contrast to this, private data members
and methods are inherited in Ruby as well. The visibility of data members and
methods is not affected by inheritance in Ruby.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;#!/usr/bin/ruby&lt;br /&gt;
&lt;br /&gt;
class Base&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def initialize&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @name = &quot;Base&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;private method
called&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; protected&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def protected_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; puts &quot;protected_method
called&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def get_name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return @name&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class Derived &amp;lt; Base&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def public_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
d = Derived.new&lt;br /&gt;
d.public_method&lt;br /&gt;
puts d.get_name&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In the example we have two classes. The Derived class
inherits from the Base class. It inherits all three methods and one data field.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;def public_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; protected_method&lt;br /&gt;
end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In the public_method of the Derived class we call one private
and one protected method. They were defined in the parent class.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;d = Derived.new&lt;br /&gt;
d.public_method&lt;br /&gt;
puts d.get_name&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;We create an instance of the Derived class. We call the
public_method. And call the get_name method, which returns the private @name
variable. Remember that all instance variables are private in Ruby. The
get_name method returns the variable regardless of the fact, that it is private
and defined in the parent class.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;$ ./inheritance3.rb&lt;br /&gt;
private method called&lt;br /&gt;
protected_method called&lt;br /&gt;
Base&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The output of the example confirms that in Ruby language,
public, protected, private methods and private member fields are inherited by
child objects from their parents.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;h2 style=&quot;line-height: 115%; margin-bottom: 4.0pt; margin-left: 0in; margin-right: 0in; margin-top: .25in;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;, serif; font-size: 11pt; line-height: 115%;&quot;&gt;The super method&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/h2&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The super method calls a method of the same name in the
parent&#39;s class. If the method has no arguments it automatically passes all its
arguments. If we write super() no arguments are passed to parent&#39;s method.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;#!/usr/bin/ruby&lt;br /&gt;
&lt;br /&gt;
class Base&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def show x=0, y=0&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &quot;Base class, x: #{x}, y:
#{y}&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Derived &amp;lt; Base&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def show x, y&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; super&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; super x&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; super x, y&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; super()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
d = Derived.new&lt;br /&gt;
d.show 3, 3&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In the example, we have two classes in a hierarchy. They both
have a show method. The show method in the Derived class calls the show method
in the Base class using the super method.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;def show x, y&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; super&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; super x&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; super x, y&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; super()&lt;br /&gt;
end&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;The super method without any arguments calls the parent&#39;s
show method with the arguments that were passed to the show method of the
Derived class. In our case x=3, y=3. The super() method passes no arguments to
the parent&#39;s show method.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;$ ./super.rb&lt;br /&gt;
&quot;Base class, x: 3, y: 3&quot;&lt;br /&gt;
&quot;Base class, x: 3, y: 0&quot;&lt;br /&gt;
&quot;Base class, x: 3, y: 3&quot;&lt;br /&gt;
&quot;Base class, x: 0, y: 0&quot;&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;Output of the example.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify; text-justify: inter-ideograph;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify; text-justify: inter-ideograph;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/2376416211732925064/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2014/10/object-oriented-programming-in-ruby.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/2376416211732925064'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/2376416211732925064'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2014/10/object-oriented-programming-in-ruby.html' title='Object-oriented programming in Ruby'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-3408172468569880049</id><published>2014-10-23T23:58:00.003-07:00</published><updated>2014-10-23T23:58:37.858-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="collect"/><category scheme="http://www.blogger.com/atom/ns#" term="inject"/><category scheme="http://www.blogger.com/atom/ns#" term="reject"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="select"/><title type='text'>What is the difference between collect,select, reject and inject in ruby? </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;What is the difference between collect,select, reject and
inject in ruby? &lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Some of the most
commonly used Enumerable&amp;nbsp; iterators are
the rhyming methods collect , select , reject , and inject .&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The
collect&amp;nbsp; method (also known as map )
executes&amp;nbsp; its associated block for each
element of the enumerable object, and collects the return values of the blocks
into an array:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
squares = [1,2,3].collect {|x| x*x} # =&amp;gt; [1,4,9]&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The
select&amp;nbsp; method invokes the associated
block for each element in the enumerable&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
object, and returns an array of elements for which the block
returns a value other than false&amp;nbsp; or nil
. For example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; evens
= (1..10).select {|x| x%2 == 0} # =&amp;gt; [2,4,6,8,10]&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The
reject&amp;nbsp; method is simply the opposite of
select ; it returns an array of elements for&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
which the block returns nil&amp;nbsp;
or false . For example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; odds =
(1..10).reject {|x| x%2 == 0} # =&amp;gt; [1,3,5,7,9]&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The
inject&amp;nbsp; method is a little more
complicated than the others. It invokes the associated&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
block with two arguments. The first argument is an
accumulated value of some sort from previous iterations. The second argument is
the next element of the enumerable object. The return value of the block
becomes the first block argument for the next iteration, or becomes the return
value of the iterator after the last iteration.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data = [2,
5, 3, 4]&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum =
data.inject {|sum, x| sum + x } # =&amp;gt; 14 (2+5+3+4)&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; floatprod =
data.inject(1.0) {|p,x| p*x } # =&amp;gt; 120.0 (1.0*2*5*3*4)&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; max =
data.inject {|m,x| m&amp;gt;x ? m : x } # =&amp;gt; 5 (largest element)&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/3408172468569880049/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2014/10/what-is-difference-between.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/3408172468569880049'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/3408172468569880049'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2014/10/what-is-difference-between.html' title='What is the difference between collect,select, reject and inject in ruby? '/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-6132730302973403414</id><published>2014-10-23T23:52:00.003-07:00</published><updated>2014-10-23T23:52:40.022-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ruby 1.8"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby 1.9"/><title type='text'>What is the difference between Ruby 1.8.7 and 1.9.2?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;What is the difference between Ruby 1.8.7 and 1.9.2?&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp; &lt;b&gt;a).Pseudo-Keyword Hash Syntax&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 6.0pt;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ruby 1.9 adds a cool feature that lets
you write things like:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foo(a: 1, b: 2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 6.0pt;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; But on Ruby 1.8, we’re stuck using the
old key =&amp;gt; value syntax:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foo(:a =&amp;gt; 1, :b =&amp;gt; 2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp; b).Multisplat Arguments&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 6.0pt;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ruby 1.9.1 offers a downright
insane amount of ways to process arguments to methods. &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def
add(a,b,c,d,e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a + b + c +
d + e&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; add(*[1,2], 3, *[4,5]) #=&amp;gt; 15&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The closest thing we can get to this on
Ruby 1.8 would be something like&amp;nbsp; this:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; add(*[[1,2], 3, [4,5]].flatten) #=&amp;gt;
15&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;c).&amp;nbsp; Block-Local Variables&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 6.0pt;&quot;&gt;
On Ruby 1.9, block variables
will shadow outer local variables, resulting in the following behavior:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;gt;&amp;gt; a = 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
=&amp;gt; 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;gt;&amp;gt; (1..10).each { |a| a }&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
=&amp;gt; 1..10&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;gt;&amp;gt; a&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
=&amp;gt; 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 6.0pt;&quot;&gt;
This is not the case on Ruby
1.8, where the variable will be modified even if not explicitly set:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;gt;&amp;gt; a = 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
=&amp;gt; 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;gt;&amp;gt; (1..10).each { |a| a }&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
=&amp;gt; 1..10&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;gt;&amp;gt; a&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
=&amp;gt; 10&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;d). Block Arguments&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 6.0pt;&quot;&gt;
In Ruby 1.9, blocks can accept
block arguments, which is most commonly seen in define_method:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
define_method(:answer) {
|&amp;amp;b| b.call(42) }&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 6.0pt;&quot;&gt;
However, this won’t work on Ruby
1.8 without some very ugly workarounds&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;h3 style=&quot;margin-left: 0in; text-indent: 0in;&quot;&gt;
&lt;span style=&quot;font-size: 12.0pt; mso-bidi-font-size: 11.0pt;&quot;&gt;e).New Proc Syntax&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/h3&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 6.0pt;&quot;&gt;
Both the stabby Proc and the .()
call are new in 1.9, and aren’t parseable by the Ruby 1.8 interpreter. This
means that calls like this need to go:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;gt;&amp;gt; -&amp;gt;(a) { a*3 }.(4)&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
=&amp;gt; 12&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 6.0pt;&quot;&gt;
Instead, use the trusty lambda
keyword and Proc#call or Proc#[]:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;gt;&amp;gt; lambda { |a| a*3 }[4]&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
=&amp;gt; 12&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;h3 style=&quot;margin-left: 0in; text-indent: 0in;&quot;&gt;
&lt;span style=&quot;font-size: 12.0pt; mso-bidi-font-size: 11.0pt;&quot;&gt;f).Using Enumerator&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/h3&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 6.0pt;&quot;&gt;
In Ruby 1.9, you can get back an
Enumerator for pretty much every method that iterates over a collection:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;gt;&amp;gt; [1,2,3,4].map.with_index { |e,i| e + i }&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
=&amp;gt; [1, 3, 5, 7]&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 6.0pt;&quot;&gt;
In Ruby 1.8, Enumerator is part
of the standard library instead of core, and isn’t quite as feature-packed.
However, we can still accomplish the same goals by being a bit more verbose:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;gt;&amp;gt; require &quot;enumerator&quot;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
=&amp;gt; true&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;gt;&amp;gt; [1,2,3,4].enum_for(:each_with_index).map { |e,i| e
+ i }&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
=&amp;gt; [1, 3, 5, 7]&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&amp;nbsp;g). String Iterators&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 6.0pt;&quot;&gt;
In Ruby 1.8, Strings are
Enumerable, whereas in Ruby 1.9, they are not. Ruby 1.9 provides String#lines,
String#each_line, String#each_char, and String#each_byte, all of which are not
present in Ruby 1.8.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&amp;nbsp;h). Character Operations&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 6.0pt;&quot;&gt;
In Ruby 1.9, strings are
generally character-aware, which means that you can index into them and get
back a single character, regardless of encoding:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;gt;&amp;gt; &quot;Foo&quot;[0]&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
=&amp;gt; &quot;F&quot;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 6.0pt;&quot;&gt;
This is not the case in Ruby
1.8.6, as you can see:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;gt;&amp;gt; &quot;Foo&quot;[0]&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
=&amp;gt; 70&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&amp;nbsp;i).Encoding Conversions&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 6.0pt;&quot;&gt;
Ruby 1.9 has built-in support
for transcoding between various character encodings, whereas Ruby 1.8 is more
limited. However, both versions support Iconv. If you know exactly what formats
you want to translate between, you can simply replace your string.encode(&quot;ISO-8859-1&quot;)
calls with something like this:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 14.15pt;&quot;&gt;
Iconv.conv(&quot;ISO-8859-1&quot;,
&quot;UTF-8&quot;, string)&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;j).Introduction of
Fibers &lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Fibers are light-weight threads with manual, cooperative scheduling, rather
than the preemptive scheduling of Ruby 1.8&#39;s threads.A fiber gets interrupted
only when it yields its execution. So a fiber is a sort of user-managed thread.
Threads use pre-emptive scheduling, whereas fibers use cooperative scheduling. &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;, serif; font-size: 12pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/6132730302973403414/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2014/10/what-is-difference-between-ruby-187-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/6132730302973403414'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/6132730302973403414'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2014/10/what-is-difference-between-ruby-187-and.html' title='What is the difference between Ruby 1.8.7 and 1.9.2?'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-1736005596608117222</id><published>2014-10-23T23:43:00.002-07:00</published><updated>2014-10-23T23:44:09.455-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="lambda"/><category scheme="http://www.blogger.com/atom/ns#" term="proc"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby blocks"/><title type='text'>What is the difference between Proc and Lambda?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;What is the difference between Proc and Lambda?&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Blocks are
syntactic structures in Ruby; they are not objects, and cannot be manipulated&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
as objects. It is possible, however, to create an object
that represents a block. Depending&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
on how the object is created, it is called a proc&amp;nbsp; or a lambda .&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Procs have
block-like behavior and lambdas have method-like behavior. Both, however, are
instances of class Proc .&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Creating &amp;amp;
invoking procs:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p =
Proc.new {|x,y| x+y }&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
p.call(1,2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Creating &amp;amp;
invoking Lamdas:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; succ =
lambda {|x| x+1}&amp;nbsp; =&amp;gt;Ruby1.8&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; succ =
-&amp;gt;(x){x&amp;gt;0} =&amp;gt;Ruby1.9&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
succ.call(1)&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%; margin-left: .5in; mso-list: l0 level1 lfo1; text-indent: -.25in;&quot;&gt;
&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;●&lt;span style=&quot;font-size: 7pt; font-stretch: normal; line-height: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In
a lambda-created proc, the return statement returns only from the proc itself&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 115%; margin-left: .5in; mso-list: l0 level1 lfo1; text-indent: -.25in;&quot;&gt;
&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;●&lt;span style=&quot;font-size: 7pt; font-stretch: normal; line-height: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;span style=&quot;font-size: 11.0pt; line-height: 115%;&quot;&gt;In
a Proc.new-created proc, the return statement is a little more surprising: it
returns control not just from the proc, &lt;b&gt;but
also from the method enclosing the proc!&lt;/b&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Differences:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoNormalTable&quot; style=&quot;border-collapse: collapse; border: none; margin-left: 2.25pt; mso-border-alt: solid black 1.0pt; mso-border-insideh: 1.0pt solid black; mso-border-insidev: 1.0pt solid black; mso-padding-alt: 0in .5pt 0in .5pt; mso-table-layout-alt: fixed; width: 665px;&quot;&gt;
 &lt;tbody&gt;
&lt;tr&gt;
  &lt;td style=&quot;border: solid black 1.0pt; padding: 2.75pt 2.75pt 2.75pt 2.75pt; width: 249.3pt;&quot; valign=&quot;top&quot; width=&quot;332&quot;&gt;&lt;div align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;Procs&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid black 1.0pt; mso-border-left-alt: solid black 1.0pt; padding: 2.75pt 2.75pt 2.75pt 2.75pt; width: 249.5pt;&quot; valign=&quot;top&quot; width=&quot;333&quot;&gt;&lt;div align=&quot;center&quot; class=&quot;MsoNormal&quot; style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;Lambda&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td style=&quot;border-top: none; border: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 2.75pt 2.75pt 2.75pt 2.75pt; width: 249.3pt;&quot; valign=&quot;top&quot; width=&quot;332&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;A proc is the
  object form of a block, and it behaves like a block.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;Calling a proc is
  like yielding to a block.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;A proc is like a
  block, so if you call a proc that executes a return&amp;nbsp; statement, it attempts&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
to return from the method that encloses the block that was
  converted to the proc. &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
For Example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
def test&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
puts &quot;entering method&quot;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
p = Proc.new { puts &quot;entering proc&quot;; return }&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
p.call&amp;nbsp; # Invoking
  the proc makes method return&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
puts &quot;exiting method&quot;&amp;nbsp; # This line is never executed&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
end&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
test&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;break to do the
  same thing like return in a proc.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp; proc handles the
  arguments it receives&amp;nbsp;
  flexibly:discarding extras, silently adding nil&amp;nbsp; for omitted arguments.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp; p = Proc.new
  {|x,y| print x,y }&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp; p.call(1,2)&amp;nbsp; # prints 1,2&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp; p.call(1)&amp;nbsp; # prints 1, nil&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-left-alt: solid black 1.0pt; mso-border-top-alt: solid black 1.0pt; padding: 2.75pt 2.75pt 2.75pt 2.75pt; width: 249.5pt;&quot; valign=&quot;top&quot; width=&quot;333&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;A lambda has
  slightly&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
modified behavior and behaves more like a method than a
  block.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;whereas calling a
  lambda is like invoking a method.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;A return&amp;nbsp; statement in a lambda returns from the
  lambda itself, not from the method that surrounds the creation site of the
  lambda:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
For Example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
def test&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
puts &quot;entering method&quot;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
p = lambda { puts &quot;entering lambda&quot;; return }&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
p.call &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;# Invoking lambda
  does not make the method #return&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
puts &quot;exiting method&quot;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
# This line *is* executed now&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
end&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
test&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
break to do the same thing like return in a lambda.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;Lambdas are not flexible
  in this way; like methods, they must be invoked with precisely&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
the number of arguments they are declared with:&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l = lambda
  {|x,y| print x,y }&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l.call(1,2)
  # This works&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l.call(1) #
  Wrong number of arguments&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; next statement works the same in a
block, proc, or lambda.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp; redo also works the
same in procs and lambdas.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&amp;nbsp; retry is never
allowed in procs or lambdas: using it always results in a LocalJumpError.&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;, serif; font-size: 12pt;&quot;&gt;&amp;nbsp;&amp;nbsp; raise behaves the same in blocks, procs, and
lambdas. Exceptions always propagate up the call stack&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/1736005596608117222/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2014/10/what-is-difference-between-proc-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/1736005596608117222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/1736005596608117222'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2014/10/what-is-difference-between-proc-and.html' title='What is the difference between Proc and Lambda?'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-1575035681499498792</id><published>2013-08-14T02:04:00.002-07:00</published><updated>2013-08-14T02:04:57.183-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="rails"/><title type='text'>dynamic programing in rails controller</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Here is the simple code snippet for dynamic programming in rails controllers.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; def method_missing(c)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; render_error(404)&lt;br /&gt;&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;The above method will be invoked when there was method missing exception was raised and we are redirected the request to specific page like 404.&lt;br /&gt;
&lt;br /&gt;
Thank You,&lt;br /&gt;
Uma Mahesh &lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/1575035681499498792/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2013/08/dynamic-programing-in-rails-controller.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/1575035681499498792'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/1575035681499498792'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2013/08/dynamic-programing-in-rails-controller.html' title='dynamic programing in rails controller'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-6023928083879737138</id><published>2013-08-14T01:07:00.001-07:00</published><updated>2013-08-14T01:07:13.042-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="git"/><title type='text'>git commands</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Here are the list of useful git commands.&lt;br /&gt;
&lt;br /&gt;
&amp;gt; git config -l&lt;br /&gt;
&lt;br /&gt;List all variables set in config file.&lt;br /&gt;
&lt;br /&gt;
&amp;gt; git config --global user.name &quot;uma mahesh&quot;&lt;br /&gt;
&amp;gt; git config --global user.email &quot;umamaheshvarma@gmail.com&quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Thank You,&lt;br /&gt;
Uma Mahesh.&lt;br /&gt;
&amp;nbsp;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/6023928083879737138/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2013/08/git-commands.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/6023928083879737138'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/6023928083879737138'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2013/08/git-commands.html' title='git commands'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-8776164002524159997</id><published>2013-07-13T00:09:00.002-07:00</published><updated>2013-07-13T00:09:32.949-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="postgres"/><title type='text'>postgresql console interface</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Here is the command to connect to postgresql through console,&lt;br /&gt;
&lt;br /&gt;
&amp;gt; sudo -u postgres psql&lt;br /&gt;
&lt;br /&gt;
The above command will connect to psql.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;nbsp; sudo -u postgres psql&lt;br /&gt;
psql (9.1.9)&lt;br /&gt;Type &quot;help&quot; for help.&lt;br /&gt;&lt;br /&gt;postgres=#&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now you can run all the sql queries through this interface.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Thank You,&lt;br /&gt;
Uma Mahesh.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/8776164002524159997/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2013/07/postgresql-console-interface.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/8776164002524159997'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/8776164002524159997'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2013/07/postgresql-console-interface.html' title='postgresql console interface'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-4491980449351903891</id><published>2013-07-10T03:02:00.003-07:00</published><updated>2013-07-10T03:02:56.950-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="rspec"/><title type='text'></title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi,&lt;br /&gt;
&lt;br /&gt;
While working with rspec I had issue as shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;undefined method `visit&#39; for #&amp;lt;RSpec::Core::ExampleGroup::Nested_5::Nested_1&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I didn&#39;t change any code modifications in the spces and my spces started failing with the error shown above. I have searched for the solution and I didn&#39;t found any specific solution for that. At last I came to find the issue is due to change in the Rspec version in my gem file.&lt;br /&gt;
&lt;br /&gt;
I reverted back to my old gem file and finally able to solve the issue.&lt;br /&gt;
&lt;br /&gt;
Thank You,&lt;br /&gt;
Uma Mahesh.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/4491980449351903891/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2013/07/undefined-method-visit-for-rspec.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/4491980449351903891'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/4491980449351903891'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2013/07/undefined-method-visit-for-rspec.html' title=''/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-3562472582505071782</id><published>2013-06-16T08:01:00.001-07:00</published><updated>2013-06-16T08:01:43.679-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Heroku"/><category scheme="http://www.blogger.com/atom/ns#" term="rails"/><category scheme="http://www.blogger.com/atom/ns#" term="twitter bootstrap"/><title type='text'>couldn&#39;t find file &#39;twitter/bootstrap&#39;</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Twitter Bootstrap in rails application not working in production while deployed to heroku.&lt;br /&gt;
&lt;br /&gt;
When I check for logs in heroku, I am able to see the below error. &lt;br /&gt;
&lt;br /&gt;
ActionView::Template::Error (couldn&#39;t find file &#39;twitter/bootstrap&#39;)&lt;br /&gt;
&lt;br /&gt;
While doing some google I came to see that, I have included&amp;nbsp; &#39;twitter-bootstrap-rails&#39; gem in development env in my gem file. So it was unable to load in production.&lt;br /&gt;
&lt;br /&gt;
I have made the &#39;twitter-bootstrap-rails&#39; gem public and bundle install again. Now every thing works fine.&lt;br /&gt;
&lt;br /&gt;
Thank You,&lt;br /&gt;
Uma Mahesh.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/3562472582505071782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2013/06/couldnt-find-file-twitterbootstrap.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/3562472582505071782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/3562472582505071782'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2013/06/couldnt-find-file-twitterbootstrap.html' title='couldn&#39;t find file &#39;twitter/bootstrap&#39;'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-728760796392394162</id><published>2013-06-16T07:50:00.000-07:00</published><updated>2013-06-16T07:50:06.354-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Heroku"/><title type='text'>sqlite3 error while pusing code to heroku</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Below is the issue while I am trying to push the code to heroku for the first time.&lt;br /&gt;
&lt;br /&gt;
rails@rails:/media/AAFA1CCBFA1C95A3/ruby/rails_app/simple_form/sample1$ git push heroku master&lt;br /&gt;Counting objects: 99, done.&lt;br /&gt;Delta compression using up to 4 threads.&lt;br /&gt;Compressing objects: 100% (88/88), done.&lt;br /&gt;Writing objects: 100% (99/99), 39.73 KiB, done.&lt;br /&gt;Total 99 (delta 3), reused 0 (delta 0)&lt;br /&gt;&lt;br /&gt;-----&amp;gt; Ruby/Rails app detected&lt;br /&gt;-----&amp;gt; Installing dependencies using Bundler version 1.3.2&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Fetching gem metadata from https://rubygems.org/.........&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Fetching gem metadata from https://rubygems.org/..&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing rake (10.0.4)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing i18n (0.6.1)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing multi_json (1.7.7)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing activesupport (3.2.13)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing builder (3.0.4)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing activemodel (3.2.13)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing erubis (2.7.0)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing journey (1.0.4)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing rack (1.4.5)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing rack-cache (1.2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing rack-test (0.6.2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing hike (1.2.3)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing tilt (1.4.1)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing sprockets (2.2.2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing actionpack (3.2.13)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing mime-types (1.23)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing polyglot (0.3.3)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing treetop (1.4.14)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing mail (2.5.4)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing actionmailer (3.2.13)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing arel (3.0.2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing tzinfo (0.3.37)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing activerecord (3.2.13)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing activeresource (3.2.13)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing rack-ssl (1.3.3)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing json (1.8.0)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing rdoc (3.12.2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing thor (0.18.1)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing railties (3.2.13)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing bootstrap-daterangepicker-rails (0.0.5)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing coffee-script-source (1.6.2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing execjs (1.4.0)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing coffee-script (2.2.0)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing coffee-rails (3.2.2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing commonjs (0.2.6)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing jquery-rails (3.0.1)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing less (2.2.1)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing less-rails (2.2.3)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing libv8 (3.3.10.4)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Using bundler (1.3.2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing rails (3.2.13)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing sass (3.2.9)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing sass-rails (3.2.6)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing simple_form (2.1.0)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Installing sqlite3 (1.3.7)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /usr/local/bin/ruby extconf.rb&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; checking for sqlite3.h... no&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sqlite3.h is missing. Try &#39;port install sqlite3 +universal&#39;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; or &#39;yum install sqlite-devel&#39; and check your shared library search path (the&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; location where your sqlite3 shared library is located).&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *** extconf.rb failed ***&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Could not create Makefile due to some reason, probably lack of&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; necessary libraries and/or headers.&amp;nbsp; Check the mkmf.log file for more&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; details.&amp;nbsp; You may need configuration options.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Provided configuration options:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --with-opt-dir&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --without-opt-dir&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --with-opt-include&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --without-opt-include=${opt-dir}/include&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --with-opt-lib&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --without-opt-lib=${opt-dir}/lib&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --with-make-prog&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --without-make-prog&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --srcdir=.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --curdir&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --ruby=/usr/local/bin/ruby&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --with-sqlite3-dir&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --without-sqlite3-dir&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --with-sqlite3-include&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --without-sqlite3-include=${sqlite3-dir}/include&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --with-sqlite3-lib&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --without-sqlite3-lib=${sqlite3-dir}/lib&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --enable-local&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --disable-local&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Gem files will remain installed in /tmp/build_27eau1y5d86jq/vendor/bundle/ruby/1.9.1/gems/sqlite3-1.3.7 for inspection.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Results logged to /tmp/build_27eau1y5d86jq/vendor/bundle/ruby/1.9.1/gems/sqlite3-1.3.7/ext/sqlite3/gem_make.out&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; An error occurred while installing sqlite3 (1.3.7), and Bundler cannot continue.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Make sure that `gem install sqlite3 -v &#39;1.3.7&#39;` succeeds before bundling.&lt;br /&gt;&amp;nbsp;!&lt;br /&gt;&amp;nbsp;!&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Failed to install gems via Bundler.&lt;br /&gt;&amp;nbsp;!&lt;br /&gt;&lt;br /&gt;&amp;nbsp;!&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Push rejected, failed to compile Ruby/Rails app&lt;br /&gt;&lt;br /&gt;To git@heroku.com:simple-form-app.git&lt;br /&gt;&amp;nbsp;! [remote rejected] master -&amp;gt; master (pre-receive hook declined)&lt;br /&gt;error: failed to push some refs to &#39;git@heroku.com:simple-form-app.git&#39;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;nbsp;Solution:&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;post-text&quot;&gt;
Add this to your Gemfile,&lt;br /&gt;


&lt;pre&gt;&lt;code&gt;group :production do
  gem &#39;pg&#39;
end
group :development, :test do
  gem &#39;sqlite3&#39;
end&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;
then do a &lt;code&gt;bundle&lt;/code&gt; then repush to heroku. You cannot use sqlite3 on Heroku - which is the cause of the error.&lt;br /&gt;
&lt;br /&gt;
Thank You,&lt;br /&gt;
Uma Mahesh.&lt;br /&gt;
&lt;br /&gt;

&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/728760796392394162/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2013/06/sqlite3-error-while-pusing-code-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/728760796392394162'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/728760796392394162'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2013/06/sqlite3-error-while-pusing-code-to.html' title='sqlite3 error while pusing code to heroku'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-3152907324985115053</id><published>2013-06-12T09:42:00.000-07:00</published><updated>2013-06-12T09:42:13.348-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Helper"/><category scheme="http://www.blogger.com/atom/ns#" term="rails console"/><title type='text'>helper method from rails console</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi,&lt;br /&gt;
&lt;br /&gt;
I would like to test the helper method from the rails console. Can any one suggest me how I can invoke a helper method from console?&lt;br /&gt;
&lt;br /&gt;
Thank You,&lt;br /&gt;
Uma Mahesh.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/3152907324985115053/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2013/06/helper-method-from-rails-console.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/3152907324985115053'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/3152907324985115053'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2013/06/helper-method-from-rails-console.html' title='helper method from rails console'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-780628497530229625</id><published>2013-05-24T00:06:00.000-07:00</published><updated>2013-05-24T00:06:53.696-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Deployment"/><category scheme="http://www.blogger.com/atom/ns#" term="rails"/><title type='text'>how to run rails console in production environment </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
We run the below command for getting into rails console.&lt;br /&gt;
&lt;br /&gt;
&amp;gt; rails c&lt;br /&gt;
&lt;br /&gt;
By default it will load the development environment. But some time you may need to run in production env to check some configuration variables.&lt;br /&gt;
&lt;br /&gt;
You can run the rails console by specific environment with the below command.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;nbsp;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; font-size: 14px; line-height: 18px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;RAILS_ENV&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; font-size: 14px; line-height: 18px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; font-size: 14px; line-height: 18px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;production rails console&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This will load the production environment setting to the console env.&lt;br /&gt;
&lt;br /&gt;
Thank You,&lt;br /&gt;
Uma Mahesh.&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/780628497530229625/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2013/05/rails-console-production-env.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/780628497530229625'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/780628497530229625'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2013/05/rails-console-production-env.html' title='how to run rails console in production environment '/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-4063995201188451558</id><published>2013-05-16T01:35:00.000-07:00</published><updated>2013-05-16T01:35:22.904-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ajax"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>Synchronous and Asynchronous difference</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi,&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;Many of the folks are quite confused about the&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;Synchronous and Asynchronous request in web application. May of us know that AJAX is an asynchronous request. But what does asynchronous mean?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;Asynchronous request will not wait for response for an request. Let me explain with an example.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;function Namecheck(){&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;var avilability = 1;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;avilability&lt;/span&gt;&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;= get_status(&quot;/user/check_name&quot;);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;if&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;avilability&lt;/span&gt;&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;&amp;nbsp;== 1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;alert(&#39;avilable&#39;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;else{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;alert(&#39;Not avilable&#39;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;In the above case &#39;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;get_status&#39; will send an ajax request to &quot;user/check_name&quot; and it will not wait for the response for that request as it is an asynchronous, there by we always get the javascript alert as &quot;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;avilable&lt;/span&gt;&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;&quot;. So the function will&amp;nbsp;execute without ant wait for response. This is how asynchronous request will work.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;Synchronous request is the one which will wait until the complete response was&amp;nbsp;received.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;Note: to over come the response issue with AJAX we will use callback to trigger a function once the complete request was done with receiving a response.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;Thank You,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 20px;&quot;&gt;Uma Mahesh&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 14px; line-height: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/4063995201188451558/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2013/05/synchronous-and-asynchronous-difference.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/4063995201188451558'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/4063995201188451558'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2013/05/synchronous-and-asynchronous-difference.html' title='Synchronous and Asynchronous difference'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-3890290363023448822</id><published>2013-05-14T03:08:00.000-07:00</published><updated>2013-05-14T03:08:19.771-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="validations"/><title type='text'>Email domain validation in ruby </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi,&lt;br /&gt;
&lt;br /&gt;
Most of the web applications will have registration forms and every form will have email field as the mandatory. We use regular expression to validate the email format. But some times we may come across tio validate the given email id was valid or not that means does the domain exists or not.&lt;br /&gt;
&lt;br /&gt;
Below is the useful code to validate the domain name in ruby with the help of MX records.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In email_validation.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
require &#39;resolv&#39;&lt;br /&gt;
&lt;br /&gt;
class EmailValidation&lt;br /&gt;
def self.validate_email_domain(email)&lt;br /&gt;
domain = email.match(/\@(.+)/)[1]&lt;br /&gt;
Resolv::DNS.open do |dns|&lt;br /&gt;
@mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)&lt;br /&gt;
end&lt;br /&gt;
puts @mx.size &amp;gt; 0 ? true : false&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
s =&amp;nbsp;EmailValidation.validate_email_domain(&quot;umamaheshvarma@gmail.com&quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above method will return true if the domain exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Thank You,&lt;br /&gt;
Uma Mahesh&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/3890290363023448822/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2013/05/email-domain-validation-in-ruby.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/3890290363023448822'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/3890290363023448822'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2013/05/email-domain-validation-in-ruby.html' title='Email domain validation in ruby '/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-5134832087320553810</id><published>2012-11-28T01:15:00.000-08:00</published><updated>2012-11-28T01:15:01.700-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ruby on rails"/><title type='text'>Guest user functionality in rails app</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi,&lt;br /&gt;
&lt;br /&gt;
In many requirements you may be asked to provide guest user functionality in application. Here are the simple steps to make that functionality simple.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
rails g migration add_guest_to_users guest:boolean&lt;br /&gt;rake db:migrate&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;index.html.erb&lt;br /&gt;&amp;lt;p&amp;gt;&amp;lt;%= button_to &quot;Guest User!&quot;, users_path, method: :post %&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;layouts/application.html.erb&lt;br /&gt;Logged in as &amp;lt;strong&amp;gt;&amp;lt;%= current_user.name %&amp;gt;&amp;lt;/strong&amp;gt;.&lt;br /&gt;&amp;lt;% if current_user.guest? %&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;%= link_to &quot;Become a member&quot;, signup_path %&amp;gt;&lt;br /&gt;&amp;lt;% else %&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;%= link_to &quot;Log Out&quot;, logout_path %&amp;gt;&lt;br /&gt;&amp;lt;% end %&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;user_controller.rb&lt;br /&gt;def create&lt;br /&gt;&amp;nbsp; @user = params[:user] ? User.new(params[:user]) : User.new_guest&lt;br /&gt;&amp;nbsp; if @user.save&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; current_user.move_to(@user) if current_user &amp;amp;&amp;amp; current_user.guest?&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; session[:user_id] = @user.id&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; redirect_to root_url&lt;br /&gt;&amp;nbsp; else&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; render &quot;new&quot;&lt;br /&gt;&amp;nbsp; end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;models/user.rb&lt;br /&gt;class User &amp;lt; ActiveRecord::Base&lt;br /&gt;&amp;nbsp; has_many :tasks, dependent: :destroy&lt;br /&gt;&lt;br /&gt;&amp;nbsp; attr_accessible :username, :email, :password, :password_confirmation&lt;br /&gt;&lt;br /&gt;&amp;nbsp; validates_presence_of :username, :email, :password_digest, unless: :guest?&lt;br /&gt;&amp;nbsp; validates_uniqueness_of :username, allow_blank: true&lt;br /&gt;&amp;nbsp; validates_confirmation_of :password&lt;br /&gt;&lt;br /&gt;&amp;nbsp; # override has_secure_password to customize validation until Rails 4.&lt;br /&gt;&amp;nbsp; require &#39;bcrypt&#39;&lt;br /&gt;&amp;nbsp; attr_reader :password&lt;br /&gt;&amp;nbsp; include ActiveModel::SecurePassword::InstanceMethodsOnActivation&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; def self.new_guest&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; new { |u| u.guest = true }&lt;br /&gt;&amp;nbsp; end&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; def name&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; guest ? &quot;Guest&quot; : username&lt;br /&gt;&amp;nbsp; end&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; def move_to(user)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tasks.update_all(user_id: user.id)&lt;br /&gt;&amp;nbsp; end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;lib/tasks/guests.rake&lt;br /&gt;namespace :guests do&lt;br /&gt;&amp;nbsp; desc &quot;Remove guest accounts more than a week old.&quot;&lt;br /&gt;&amp;nbsp; task :cleanup =&amp;gt; :environment do&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; User.where(guest: true).where(&quot;created_at &amp;lt; ?&quot;, 1.week.ago).destroy_all&lt;br /&gt;&amp;nbsp; end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;By applying above simple steps you can add guest user functionality in existing rails application easily .&lt;br /&gt;&lt;br /&gt;Thank You,&lt;br /&gt;Uma Mahesh.&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/5134832087320553810/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2012/11/guest-user-functionality-in-rails-app.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/5134832087320553810'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/5134832087320553810'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2012/11/guest-user-functionality-in-rails-app.html' title='Guest user functionality in rails app'/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1352368109032127573.post-5823132159450236830</id><published>2012-11-28T00:00:00.001-08:00</published><updated>2012-11-28T00:01:23.886-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ruby"/><title type='text'>ruby 1.9.3 perfomance </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi,&lt;br /&gt;
&lt;br /&gt;
Recently I have read article about ruby performance issue compared to ruby 1.9.2 and ruby 1.9.3 and came to see few important points that need to be noted. Below is the discussion.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-attachment: initial; background-clip: initial; background-color: #fafafa; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; margin-bottom: 22px; margin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;
We just switched a site from Apache + ruby 1.9.2 to nginx + ruby 1.9.3 a few days ago and I noticed that somehow the site speed has noticably dropped on the ruby side of things and I just couldn’t understand why. &lt;/div&gt;
&lt;div style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-attachment: initial; background-clip: initial; background-color: #fafafa; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; margin-bottom: 22px; margin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;
&lt;code style=&quot;background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #993333; font-family: Monaco, monospace; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 1px; padding-left: 5px; padding-right: 5px; padding-top: 1px; vertical-align: baseline;&quot;&gt;&lt;br /&gt;/opt/nginx/logs# rvm use 1.9.3&lt;br /&gt;Using /usr/local/rvm/gems/ruby-1.9.3-p327&lt;br /&gt;/opt/nginx/logs# time ruby -e &quot;count = 0; while(count &amp;lt; 100000000); count = count + 1; end; puts count&quot;&lt;br /&gt;100000000&lt;/code&gt;&lt;/div&gt;
&lt;div style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-attachment: initial; background-clip: initial; background-color: #fafafa; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; margin-bottom: 22px; margin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;
real 0m7.655s&lt;br /&gt;
user 0m7.632s&lt;br /&gt;
sys 0m0.012s&lt;/div&gt;
&lt;div style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-attachment: initial; background-clip: initial; background-color: #fafafa; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; margin-bottom: 22px; margin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;
/opt/nginx/logs# rvm use 1.9.2&lt;br /&gt;
Using /usr/local/rvm/gems/ruby-1.9.2-p320&lt;br /&gt;
/opt/nginx/logs# time ruby -e &quot;count = 0; while(count &amp;lt; 100000000); count = count + 1; end; puts count&quot;&lt;br /&gt;
100000000&lt;/div&gt;
&lt;div style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-attachment: initial; background-clip: initial; background-color: #fafafa; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; margin-bottom: 22px; margin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;
real 0m4.716s&lt;br /&gt;
user 0m4.716s&lt;br /&gt;
sys 0m0.000s&lt;/div&gt;
&lt;div style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-attachment: initial; background-clip: initial; background-color: #fafafa; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; margin-bottom: 22px; margin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;
Checking make.log showed that 1.9.3 was indeed compiled w/o any optimizations. After I hand-compiled a 1.9.3, I got this:&lt;/div&gt;
&lt;div style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-attachment: initial; background-clip: initial; background-color: #fafafa; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; margin-bottom: 22px; margin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;
&lt;code style=&quot;background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #993333; font-family: Monaco, monospace; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 1px; padding-left: 5px; padding-right: 5px; padding-top: 1px; vertical-align: baseline;&quot;&gt;&lt;br /&gt;/opt/ruby193opt/bin# ./ruby -v&lt;br /&gt;ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]&lt;br /&gt;/opt/ruby193opt/bin# time ./ruby -e &quot;count = 0; while(count &amp;lt; 100000000); count = count + 1; end; puts count&quot;&lt;br /&gt;100000000&lt;/code&gt;&lt;/div&gt;
&lt;div style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-attachment: initial; background-clip: initial; background-color: #fafafa; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; margin-bottom: 22px; margin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;
real 0m4.641s&lt;br /&gt;
user 0m4.628s&lt;br /&gt;
sys 0m0.008s&lt;/div&gt;
&lt;div style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-attachment: initial; background-clip: initial; background-color: #fafafa; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; margin-bottom: 22px; margin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;
/opt/ruby193opt/bin# ruby -v&lt;br /&gt;
ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-linux]&lt;br /&gt;
puck352:/opt/ruby193opt/bin# time ruby -e &quot;count = 0; while(count &amp;lt; 100000000); count = count + 1; end; puts count&quot;&lt;br /&gt;
100000000&lt;/div&gt;
&lt;div style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-attachment: initial; background-clip: initial; background-color: #fafafa; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; margin-bottom: 22px; margin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;
real 0m4.634s&lt;br /&gt;
user 0m4.624s&lt;br /&gt;
sys 0m0.012s&lt;/div&gt;
&lt;div style=&quot;-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-attachment: initial; background-clip: initial; background-color: #fafafa; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-family: Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; margin-bottom: 22px; margin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: -webkit-auto; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;
Now it performs on par with 1.9.2&lt;/div&gt;
&lt;div style=&quot;background-color: #fafafa; border-width: 0px; color: black; font-family: Arial,sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; margin: 0px 0px 22px; orphans: 2; outline-width: 0px; padding: 0px; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;
&amp;nbsp;Thank You,&lt;br /&gt;
Uma Mahesh.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://railsknowledge.blogspot.com/feeds/5823132159450236830/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://railsknowledge.blogspot.com/2012/11/ruby-193-perfomance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/5823132159450236830'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1352368109032127573/posts/default/5823132159450236830'/><link rel='alternate' type='text/html' href='http://railsknowledge.blogspot.com/2012/11/ruby-193-perfomance.html' title='ruby 1.9.3 perfomance '/><author><name>railsknowledge</name><uri>http://www.blogger.com/profile/14530825424864571440</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>