What you are trying to do is certainly possible. You are correct when you point to ActiveRecord::Inflector as something that works similarly. This approach modifies the Fixnum class itself to add new methods and although I don't generally recommend ad-hoc patching of core classes, you can see it in action in active_support/core_ext/integer/inflections.rb :
require 'active_support/inflector'
class Integer
# Ordinalize turns a number into an ordinal string used to denote the
# position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
#
# 1.ordinalize # => "1st"
# 2.ordinalize # => "2nd"
# 1002.ordinalize # => "1002nd"
# 1003.ordinalize # => "1003rd"
# -11.ordinalize # => "-11th"
# -1001.ordinalize # => "-1001st"
#
def ordinalize
ActiveSupport::Inflector.ordinalize(self)
end
end
In your case I might do something like:
module WeekdayInflector
def weekday
Date::DAYNAMES[self]
end
end
class Fixnum
include WeekdayInflector
end
which will at least help others track down the methods you added by looking at the module. Please note that this will affect ALL instances of Fixnum and could lead to conflicts if you include a Gem that tries to do the same thing. It is worth asking whether this tradeoff is worth it or if defining a simple view helper is the better way to go.
2.my_module_methodto return"Tuesday"?wdayto get the integer value of a day.Like this exampleDateTime.parse("Tuesdayy").wday #=> 3. And if you want the day,just useyourdateObj.strftime('%A').No need of these conversions.def dayname Date::DAYNAMES[weekday] endand on call attribute withdayname