Starter Step

Archive for November 2009

I wrote this as a plugin….but it really has nothing to do with rails. I guess it could be packaged as a gem, but its so small that it probably doesn’t make sense. You ever create class variables or class instance variables and then create getters for them for use as statics?

Old Way:

class MyClass
  @items = [1,2,3]

  def self.items
    @items
  end
end

MyClass.items  #[1,2,3]

New Way:

class MyClass
  has_class_attr :items, :data => [1,2,3]
end

MyClass.items  #[1,2,3]

Install:

  .script/plugin install git://github.com/angelo0000/has_class_attr.git
Advertisements

Building on my previous post I created the has_duration_field plugin. As described, I wanted to represent a duration of time on a field in my model. Using the proxy_field plugin, I built the DurationField class and added it as the proxy for my columns tblk and tduty.

Before the has_duration_field plugin:

class Block < ActiveRecord::Base
  proxy_field [:tduty, :tblk], :as => DurationField
end

I just implemented my DurationField class and threw it in my lib dir. As I did that I realized that really using proxy_field and the implementation of DurationField would make a neat little plugin.

With the plugin you can do this:

class Block < ActiveRecord::Base
  has_duration_field [:tduty, :tblk]
end

The plugin just provides an implementation of the DurationField class for you and an easy way to make your column proxy to a DurationField.

Install:

./script/plugin install git://github.com/angelo0000/has_duration_field.git


  • Dave: I can tell you're a ruby guy because you forgot the 'return' keyword. Thanks for the tip though!
  • Chandrashekhar H M: Hi, Thanks its working fine in iOS 6 but not in iOS 7.0. Any Suggestion on this.
  • Coeur: To change a rootViewController, without all this TVNavigationController : myNewRoot = [[UIViewController alloc] init]; myNavigationController.view