Jason Hsu, Android developer
2013-Apr-23 14:59 UTC
Examples of long AND WELL-WRITTEN Ruby scripts
I''m looking for examples of Ruby scripts that are long AND well-written. I have a Ruby script for scraping information on stock ETFs and mutual funds and storing the data in a Postgres database at https://github.com/jhsu802701/bsf-scrape/blob/master/scrape.rb . While I need to make some minor changes to it (like providing external options to choose between the long and short version, as the "Enter blahblahblah within 20 seconds" approach doesn''t work in a cron job), I know I need to make one major change: making the script better-written. Substantial parts of my script are cobbled together from examples of code for performing various tasks. (I''m quite new to Ruby.) I know that my script is far from optimal. What long Ruby scripts are considered to be the gold standards in Ruby style and techniques? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/SUsbmVAVbR8J. For more options, visit https://groups.google.com/groups/opt_out.
On Apr 23, 2013, at 10:59 AM, Jason Hsu, Android developer wrote:> I''m looking for examples of Ruby scripts that are long AND well-written. > > I have a Ruby script for scraping information on stock ETFs and mutual funds and storing the data in a Postgres database at https://github.com/jhsu802701/bsf-scrape/blob/master/scrape.rb . While I need to make some minor changes to it (like providing external options to choose between the long and short version, as the "Enter blahblahblah within 20 seconds" approach doesn''t work in a cron job), I know I need to make one major change: making the script better-written. > > Substantial parts of my script are cobbled together from examples of code for performing various tasks. (I''m quite new to Ruby.) I know that my script is far from optimal. What long Ruby scripts are considered to be the gold standards in Ruby style and techniques?Long scripts may be the entire problem right there. A lot of the "masterful" Ruby I have seen is really brief, not long at all. If a method takes more than a handful of lines, it gets refactored into two or more shorter methods, these get organized into sensibly-designed classes, and no single script gets responsibility for more than one thing. I am in no way qualified to write like this, but I have seen it enough times to know that it''s what I should be reaching for in my own work. Open up @tenderlove''s CSSPool project, which parses CSS into Ruby objects. It''s pretty hard to find a method more than 4 lines long anywhere within it. Walter> > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/SUsbmVAVbR8J. > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Jason Hsu, Android developer
2013-Apr-23 19:18 UTC
Re: Examples of long AND WELL-WRITTEN Ruby scripts
Walter, I''ve looked at the Ruby source code of a few games, and I''m starting to see what you''re talking about. I see that more experienced Ruby developers don''t cram everything into one file like I did. I see that I should be giving each class its own file, and I should be using Modules. I see that there are Ruby scripts that use a Gemfile but not Rails. (Is there a "ruby generate" or "ruby new" command analogous to "rails generate" and "rails new"?) What do you think of Conway''s Game of Life at https://github.com/spaghetticode/game-of-life-ruby ? I''ve tried it out, so I know it works. Does the source code set an example of coding practices to emulate? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/zblw-jd3WWwJ. For more options, visit https://groups.google.com/groups/opt_out.
No, there is no "ruby generate" or "ruby new" commands that would generate a skeleton program. Ruby itself is just like any other compiled on the fly interpreted programming language. You can simply write code in a text file and execute it via the ruby interpreter. Rails on the otherhand is a collection of Ruby scripts arranged in such a way that the default conventions somewhat require it to be organized in such a way to keep it as simple as possible. A suggestion when creating ruby programs it is convenient to keep it modular, ie. do not have everything in one .rb file. sort things out it makes life so much easier if you ever need to make changes remove or implement new capabilities to your program. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/IH9pBjOtNboJ. For more options, visit https://groups.google.com/groups/opt_out.
tamouse mailing lists
2013-Apr-27 04:43 UTC
Re: Re: Examples of long AND WELL-WRITTEN Ruby scripts
On Thu, Apr 25, 2013 at 10:18 AM, Pat Johnson <p.johnson125-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> No, there is no "ruby generate" or "ruby new" commands that would generate a > skeleton program. Ruby itself is just like any other compiled on the fly > interpreted programming language. You can simply write code in a text file > and execute it via the ruby interpreter. Rails on the otherhand is a > collection of Ruby scripts arranged in such a way that the default > conventions somewhat require it to be organized in such a way to keep it as > simple as possible. A suggestion when creating ruby programs it is > convenient to keep it modular, ie. do not have everything in one .rb file. > sort things out it makes life so much easier if you ever need to make > changes remove or implement new capabilities to your program.As far as generators go, there actually are a few. The ones I''m most familiar with generate directory and file structure, and have some opinions about where best to place things. These are a few I use: - bundler gem gemname - methadone [options] cliappname - GLI [options] clisappsuitename The thor gem talks about it''s use as a generator tool as well. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.