<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Also, keep in mind that ObjectSpace is disabled by default on JRuby for performance reasons and they don't recommend enabling it again (although it turns out it works on JRuby locally, so maybe something has changed).<div><br></div><div><a href="http://ola-bini.blogspot.in/2007/07/objectspace-to-have-or-not-to-have.html">http://ola-bini.blogspot.in/2007/07/objectspace-to-have-or-not-to-have.html</a></div><div><a href="http://kenai.com/projects/jruby/pages/PerformanceTuning#Disabling_ObjectSpace">http://kenai.com/projects/jruby/pages/PerformanceTuning#Disabling_ObjectSpace</a></div><div><br></div><div>Thanks,</div><div>Srushti</div><div><a href="http://c42.in">http://c42.in</a><br><div>
</div>
<br><div><div>On 14-Mar-2013, at 11:15 AM, Srushti Ambekallu wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Collapsing that down you could do:<div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>subclasses = <span class="Apple-tab-span" style="white-space:pre">ObjectSpace.each_object </span>do <span class="Apple-tab-span" style="white-space:pre">|k</span>lass<span class="Apple-tab-span" style="white-space:pre">|</span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>if <span class="Apple-tab-span" style="white-space:pre">k</span>lass<span class="Apple-tab-span" style="white-space:pre">.is_a?(Class) && </span><span class="Apple-tab-span" style="white-space:pre">k</span>lass<span class="Apple-tab-span" style="white-space:pre">.ancestors.include?</span>(Ohm::Model<span class="Apple-tab-span" style="white-space:pre">)</span> && klass.instance_methods.include?(:created_at) && klass.instance_methods.include?(:updated_at)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span># do the conversion</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>end</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>end</div><div><br></div><div>Or you could put that into a method and parameterise "Ohm::Model" so that it can be reused for other classes too.</div><div><br></div><div>Thanks,</div><div>Srushti</div><div><a href="http://c42.in/">http://c42.in</a><br><div><div>
</div>
<br><div><div>On 14-Mar-2013, at 8:10 AM, Ronny Ager-Wick wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
<div bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Thanks, Jon,<br>
this is practically what I asked for - a list of all of the
objects I need, and a few more. For some reason I got an error on
the last line.
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<a href="https://gist.github.com/JonRowe/5158141#comment-797997">https://gist.github.com/JonRowe/5158141#comment-797997</a>
Not to worry though, with all the information I got, I'm well on
my way to a solution.<br>
Ronny.<br>
<br>
<br>
On 14/03/13 09:42, Jon Rowe wrote:<br>
</div>
<blockquote cite="mid:C4975E7F25E74ABCA2723CD49812F114@jonrowe.co.uk" type="cite">
<div style="font-family: Helvetica; font-size: 13px; ">
<div>You can get the constants of Object or some other top level
object, map them into the actual constants (cause Ruby returns
them as symbols),and then filter them…</div>
<div><br>
</div>
<div>Something along the lines of this… <a moz-do-not-send="true" href="https://gist.github.com/JonRowe/5158141">https://gist.github.com/JonRowe/5158141</a></div>
</div>
<div>
<div><br>
</div>
<div><span style="font-size: 10pt; ">Jon Rowe</span></div>
<div><span style="font-size: 10pt; ">-----------------------------</span></div>
<div><span style="font-size: 10pt; "><a class="moz-txt-link-abbreviated" href="mailto:mail@jonrowe.co.uk">mail@jonrowe.co.uk</a></span></div>
<div><span style="font-size: 10pt; ">jonrowe.co.uk</span></div>
<div><br>
</div>
</div><p style="color: #A0A0A8;">On Thursday, 14 March 2013 at 11:38,
Ronny Ager-Wick wrote:</p>
<blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
<span>
<div>
<div>
<div>I've been trying to find a way to do this, but I may
be searching for the </div>
<div>wrong terms or something because I get nowhere, even
with the help of my </div>
<div>friend Google.</div>
<div>I want to loop through the defined classes to see
which ons of them responds </div>
<div>to certain methods.</div>
<div>The classes I'm trying to find are Ohm Models that
have a certain attribute </div>
<div>defined.</div>
<div>If I had a collection of classes, I'd probably do
something like this:</div>
<div><br>
</div>
<div>classes = #get list of all classes</div>
<div>classes.each { |c|</div>
<div> # assume it's an Ohm::Model if it responds to :first</div>
<div> # maybe there's a better way of filtering out only
the Ohm models</div>
<div> if c.respond_to?(:first) &&
c.first.respond_to?(:updated_at)</div>
<div> # convert the timestamp of all records in this
model.</div>
<div> end</div>
<div>end</div>
<div><br>
</div>
<div>The end objective is to convert the timestamp from
the old way they used to </div>
<div>store it (Ohm-contrib 0.*) which looks like this
"2011-02-25 21:54:06 UTC", </div>
<div>and the new way, which are UNIX timestamps.</div>
<div>I could always just make a list of the models
manually and loop through them, </div>
<div>but I want to make a reusable script that others can
benefit from as well.</div>
<div>Ronny.</div>
<div>_______________________________________________</div>
<div>Chat mailing list</div>
<div><a moz-do-not-send="true" href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a></div>
<div><a moz-do-not-send="true" href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a></div>
</div>
</div>
</span> </blockquote>
<div> <br>
</div>
</blockquote>
<br>
</div>
_______________________________________________<br>Chat mailing list<br>Chat@lists.lrug.org<br>http://lists.lrug.org/listinfo.cgi/chat-lrug.org<br></blockquote></div><br></div></div></div></blockquote></div><br></div></body></html>