I''d like to see if an object is of a certain type. The following works but I''m sure there''s a better way: myobject.class.to_s == "String" Did a quick search on the Pickaxe book but didn''t find anything. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Try myobject.is_a? String Jacob On 9/8/05, Hammed Malik <hammed@gmail.com> wrote:> I'd like to see if an object is of a certain type. The following works but > I'm sure there's a better way: > > myobject.class.to_s == "String" > > Did a quick search on the Pickaxe book but didn't find anything. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
>myobject.is_a? StringI LOVE Ruby! :) On 9/8/05, Jacob Quinn Shenker <jqshenker-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Try > myobject.is_a? String > > Jacob > > On 9/8/05, Hammed Malik <hammed-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I''d like to see if an object is of a certain type. The following works > but > > I''m sure there''s a better way: > > > > myobject.class.to_s == "String" > > > > Did a quick search on the Pickaxe book but didn''t find anything. > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > >-- Hammed Malik _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> >myobject.is_a? String > > I LOVE Ruby! :)I''m just curious under what situation calls for you to actually be wanting to check the type of objects? As far as I understand, Ruby allows you to add new methods to existing classes, just like Smalltalk, which means you can mostly do away with type checking, and instead use polymorphism (aka duck typing) Its what I would suggest you do. Unless you absolutely positively can think of no other way to deal with your particular situation. Regards,
Sean, I was using Sebastian Kanthak''s file_column library and kept getting a undefined method `original_filename'' for "image.gif":String error because I had forgotten to set the multipart attribute for the form tag and a String object was being passed instead of a File object. To avoid this in future, I''ve added raise "Form must be Multipart" if file.is_a? String just before ''original_filename'' is called on the object. On 9/9/05, Sean Malloy <smalloy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > >myobject.is_a? String > > > > I LOVE Ruby! :) > > I''m just curious under what situation calls for you to actually be > wanting to check the type of objects? > > As far as I understand, Ruby allows you to add new methods to existing > classes, just like Smalltalk, which means you can mostly do away with > type checking, and instead use polymorphism (aka duck typing) > > Its what I would suggest you do. Unless you absolutely positively can > think of no other way to deal with your particular situation. > > Regards, > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Hammed Malik _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Just replying back to the list. When I replied I sent it directly to you rather than back to the list Only caveat that I would suggest with regards to adding methods to the base system... It is a powerful and useful feature because it enables you to build up a code base that is specific for a particular application, and really solves you _ever_ having to do any type checking (because you can always add methods to existing classes).. You can end up going crazy and adding methods to existing classes every where, and you end up confusing yourself more than helping. I tend to only add methods to existing objects _if_ I need to do type checking to execute some piece of conditional logic. In Java sometimes you just _have_ to do type checks to execute conditional code. On 9/9/05, Hammed Malik <hammed-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks! I agree this is a better way to handle it. > > It''s going to take me a while to stop thinking in java. > > > > > If it was me, I would add original_filename to String > > > > def original_filename > > raise "Form must be Multipart" > > end > >
What would you say is a good way to excute some code only for a particular type of object without type checking? Adding methods to all other possible objects could get unweildy. On 9/9/05, Sean Malloy <smalloy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Just replying back to the list. When I replied I sent it directly to > you rather than back to the list > > Only caveat that I would suggest with regards to adding methods to the > base system... It is a powerful and useful feature because it enables > you to build up a code base that is specific for a particular > application, and really solves you _ever_ having to do any type > checking (because you can always add methods to existing classes).. > You can end up going crazy and adding methods to existing classes > every where, and you end up confusing yourself more than helping. I > tend to only add methods to existing objects _if_ I need to do type > checking to execute some piece of conditional logic. In Java sometimes > you just _have_ to do type checks to execute conditional code. > > On 9/9/05, Hammed Malik <hammed-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Thanks! I agree this is a better way to handle it. > > > > It''s going to take me a while to stop thinking in java. > > > > > > > > If it was me, I would add original_filename to String > > > > > > def original_filename > > > raise "Form must be Multipart" > > > end > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Hammed Malik _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> What would you say is a good way to excute some code only for a particular > type of object without type checking? Adding methods to all other possible > objects could get unweildy.keep in mind you don''t need to define the method on _all_ other classes, only Object. So if you had a particular piece of code that checked for a User.. if object.is_a? User then @weighting = 10 else if object.is_a? Teacher @weighting = 5 else @weighting = 0 end I would structure it like so.,.. class Object def weighting 0 end end class User def weighting 10 end end class Teacher def weighting 5 end end and your calling code does away with the conditional, and instead just looks like so: @weighting = object.weighting Now if you identify another object, which needs a slightly different weighting, its easy to add it, and there is no conditional logic to introduce. In Java, if you wanted to add weightings to your object model, you would have no choice but to eventually use some form of type checking, because you can only add methods to your own classes. This particular feature is one of my favourite in Smalltalk/Ruby. At first I was hesitant to modify existing classes, but now, if I have to do any C#... Well, you know where I''m headed with this comment!
Andrew Stuart
2005-Sep-09 07:19 UTC
No one interested in DB2 drivers for Ruby - what does it mean?
Hello Folks, A few days ago I invited people to email Grant Hutchison from IBM if they have any interest in IBM developing "official" Ruby drivers for DB2. Grant says that only two people sent an email expressing interest, and one was from IBM! I wonder what this means - that Ruby people aren''t developing for DB2 because there aren''t enterprise endorsed DB2 drivers, or that DB2 is just not as accessible to Ruby developers as MySQL or Postgres. Or maybe something else? Anyway it''s a bit of a disappointment because I was hoping to be able to develop applications that take advantage of DB2''s powerful row level access control security. Are there any Ruby people out there who use DB2? Andrew Stuart
David Mitchell
2005-Sep-09 11:36 UTC
Re: No one interested in DB2 drivers for Ruby - what does it mean?
Hi list and Grant, I would be interested in DB2/Ruby drivers if they existed, but the number of times I''ve come across DB2 where I would have had the choice to use Ruby are very few. I''m not about to recommend technology as fluid/immature as Rails for something like an Internet banking app, and banks are where I come across DB2 most often. For whatever reason, although I come across DB2 fairly regularly, Oracle and SQL Server are by far the commercial DBs I encounter most often when developing (or managing the development of) Web apps. I''d love it if DB2/Ruby drivers existed, and it''d make me consider DB2 as an alternative to Oracle when I''m in a position to recommend a (commercial) DB product, but I don''t know that I actually see DB2 that often in the Web app space to justify the effort. Anyone else? Regards Dave M. On 9/9/05, Andrew Stuart <andrew.stuart-TWq/lk6o2i4FZYWR8B6FNDvXrrhHudLZEK66K81epY8@public.gmane.org> wrote:> Hello Folks, > > A few days ago I invited people to email Grant Hutchison from IBM if they > have any interest in IBM developing "official" Ruby drivers for DB2. > > Grant says that only two people sent an email expressing interest, and one > was from IBM! > > I wonder what this means - that Ruby people aren''t developing for DB2 > because there aren''t enterprise endorsed DB2 drivers, or that DB2 is just > not as accessible to Ruby developers as MySQL or Postgres. Or maybe > something else? > > Anyway it''s a bit of a disappointment because I was hoping to be able to > develop applications that take advantage of DB2''s powerful row level access > control security. > > Are there any Ruby people out there who use DB2? > > Andrew Stuart > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
M. Edward (Ed) Borasky
2005-Sep-09 13:34 UTC
Re: No one interested in DB2 drivers for Ruby - what does it mean?
Andrew Stuart wrote:>Hello Folks, > >A few days ago I invited people to email Grant Hutchison from IBM if they >have any interest in IBM developing "official" Ruby drivers for DB2. > >Grant says that only two people sent an email expressing interest, and one >was from IBM! > >I wonder what this means - that Ruby people aren''t developing for DB2 >because there aren''t enterprise endorsed DB2 drivers, or that DB2 is just >not as accessible to Ruby developers as MySQL or Postgres. Or maybe >something else? > ><pregnant pause> Is DB2 open source?>Anyway it''s a bit of a disappointment because I was hoping to be able to >develop applications that take advantage of DB2''s powerful row level access >control security. > >If DB2 isn''t open source, is this a useful feature that should be in PostgreSQL or MySQL?>Are there any Ruby people out there who use DB2? > >I think the question is "are there DB2 people who use (or would like to use -- or who would be allowed to use) Ruby?" -- M. Edward (Ed) Borasky http://www.borasky-research.net/ http://borasky-research.blogspot.com/ http://pdxneurosemantics.com http://pdx-sales-coach.com http://algocompsynth.com
Andrea Campi
2005-Sep-09 14:18 UTC
Re: No one interested in DB2 drivers for Ruby - what does it mean?
Andrew, On Fri, Sep 09, 2005 at 05:19:15PM +1000, Andrew Stuart wrote:> Hello Folks, > > A few days ago I invited people to email Grant Hutchison from IBM if they > have any interest in IBM developing "official" Ruby drivers for DB2.[...]> Are there any Ruby people out there who use DB2?I missed your email regarding the petition. The company I work for is an important customer for IBM in Italy, and we use DB2 on AIX for all out critical data. We have just deployed our first internal app on Rails, and we''re interfacing with DB/2 with no problem at all. A couple of patches were needed to get all the Rails goodness, and sadly after posting them to the Rails issue tracking system I haven''t been able to follow up so they can be included in Rails; but apart from that, thing just work in the current state. What exactly is missing from your POV? Is that just the IBM stamp you''re looking for? Not that I wouldn''t like that, mind you; just to make sure I get your point. Bye, Andrea -- Press every key to continue.
Wilson Bilkovich
2005-Sep-09 14:29 UTC
Re: No one interested in DB2 drivers for Ruby - what does it mean?
On 9/9/05, Andrew Stuart <andrew.stuart-TWq/lk6o2i4FZYWR8B6FNDvXrrhHudLZEK66K81epY8@public.gmane.org> wrote:> > I wonder what this means - that Ruby people aren''t developing for DB2 > because there aren''t enterprise endorsed DB2 drivers, or that DB2 is just > not as accessible to Ruby developers as MySQL or Postgres. Or maybe > something else?Another possibility that comes to mind is that because Rails doesn''t run on z/Series boxes, people are less likely to make use of this combination. If you could link your Rails app and DB2 database via transactions managed by RRS, it would start to look like a more serious ''enterprise'' option. Personally, I rarely encounter anything other than Oracle or MS SQL Server (ugh). --Wilson.
Steve Downey
2005-Sep-09 14:35 UTC
Re: No one interested in DB2 drivers for Ruby - what does it mean?
Andrew Stuart wrote:>Hello Folks, > >A few days ago I invited people to email Grant Hutchison from IBM if they >have any interest in IBM developing "official" Ruby drivers for DB2. > >Grant says that only two people sent an email expressing interest, and one >was from IBM! > > >I guess that makes me the non-IBM person. My guess is that the majority of the people using RoR right now are individuals or small companies that have embraced open source, or perhaps individuals in large companies where there is an open source skunk works with Linux, MySql, etc. The typical shop using DB2 is more likely to be larger, more corporate, less open-source-inclined and have developers with Windows desktops ... and there lies the problem. A lot of the Ruby modules require a C-compiler which the typical Windows desktop developer doesn''t have. I tried in vain to get the DB2 client working (with much help from a few people), but no luck. I also need to interact with our LDAP directory but couldn''t get the Ruby LDAP stuff working on my Windows machine. There was a thread yesterday about ease of installation. If the Ruby/Rails windows users were made as whole as the *nix users I would predict a doubling of usage. Windows users are spoiled by easy installers and precompiled binaries. And suggesting "if you want ''x'' build it" isn''t very helpful when 1) folks are working on their own time on a project to get it accepted by the PHBs, 2) don''t have the time, 3) don''t have the experience if they have the time.
zedshaw-dd7LMGGEL7NBDgjK7y7TUQ@public.gmane.org
2005-Sep-09 18:44 UTC
Re: No one interested in DB2 drivers for Ruby - what does it mean?
Whoa! I missed this. I''m writing a Ruby on Rails appliation for a pretty big IBM customer and will need DB2. I''ll try to find the e-mail address for Mr. Hutchinson. Keep in mind one thing though: IBM make a *lot* of money off their Java solutions. Zed A. Shaw http://www.zedshaw.com/> Hello Folks, > > A few days ago I invited people to email Grant Hutchison from IBM if they > have any interest in IBM developing "official" Ruby drivers for DB2. > > Grant says that only two people sent an email expressing interest, and one > was from IBM! > > I wonder what this means - that Ruby people aren''t developing for DB2 > because there aren''t enterprise endorsed DB2 drivers, or that DB2 is just > not as accessible to Ruby developers as MySQL or Postgres. Or maybe > something else? > > Anyway it''s a bit of a disappointment because I was hoping to be able to > develop applications that take advantage of DB2''s powerful row level > access > control security. > > Are there any Ruby people out there who use DB2? > > Andrew Stuart > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >