tag:blogger.com,1999:blog-11788780.post1734789726589432140..comments2023-12-29T13:22:33.104-08:00Comments on JJinuxLand: Ruby: All Your Method are Belong to Mejjinuxhttp://www.blogger.com/profile/03270879497119114175noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-11788780.post-56867956797737918612007-08-28T15:13:00.000-07:002007-08-28T15:13:00.000-07:00private, protected, and public have a purpose: the...private, protected, and public have a purpose: they keep folks away from the unstable parts of your API.<BR/><BR/>It's a very, very good thing to have a means by which you can keep programmers from inadvertently <STRONG>depending</STRONG> on what should be refactorable. That's what we're doing when we declare something private, we're saying "it may go away in a .x revision"Josh Petershttps://www.blogger.com/profile/01492626254706129536noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-82761096244324400652007-08-21T16:23:00.000-07:002007-08-21T16:23:00.000-07:00> In short, trust the programmer.I agree. Thanks ...> In short, trust the programmer.<BR/><BR/>I agree. Thanks for the comment ;)jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-37625390702270127302007-08-21T16:22:00.000-07:002007-08-21T16:22:00.000-07:00> Well, given security constraints are not set you...> Well, given security constraints are not set you can call private java method (using reflection and setAccessible(boolean))<BR/><BR/>That's so awesome ;) Thanks for the comment!jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-62061626807315192792007-08-20T17:30:00.000-07:002007-08-20T17:30:00.000-07:00The intent in 1.9 is supposedly to switch it so th...The intent in 1.9 is supposedly to switch it so that send does respect private vs non-private, and a different version (I think last I checked it was __send__) does not. The clearest way to get an instance variable, by the way, is instance_variable_get:<BR/><BR/>obj.instance_variable_get :@a<BR/><BR/>Similarly, you can set them via instance_variable_set. It turns out that the approach that it is `just a suggestion' is a common one in Ruby: show convention, but allow the programmer the flexibility to achieve what they want without getting in the way. In short, trust the programmer. This is a concept that is completely alien to Java's approach -- and that's why Java is usually better suited to the so-called `enterprise', where you often meet subpar coders who would blow entire cities up accidentally if they had the flexibility that Ruby provides.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11788780.post-58795592706059157192007-08-20T14:48:00.000-07:002007-08-20T14:48:00.000-07:00Well, given security constraints are not set you c...Well, given security constraints are not set you can call private java method (using reflection and setAccessible(boolean))Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11788780.post-34785097462909951542007-08-20T03:12:00.000-07:002007-08-20T03:12:00.000-07:00Wow, even #send doesn't enforce the constraints? ...Wow, even #send doesn't enforce the constraints? That's crazy ;)jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-31555528154976571062007-08-19T08:12:00.000-07:002007-08-19T08:12:00.000-07:00Or #send.obj.send(:private_method)Or #send.<BR/><BR/>obj.send(:private_method)Tomhttps://www.blogger.com/profile/17279815292023249373noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-44453757480641830782007-08-18T22:31:00.000-07:002007-08-18T22:31:00.000-07:00You can also use instance_eval to get at instance ...You can also use instance_eval to get at instance variables:<BR/><BR/>obj.instance_eval { @a }Anonymousnoreply@blogger.com