Level Up Coding

Coding tutorials and news. The developer homepage gitconnected.com && skilled.dev && levelup.dev

Follow publication

Rails Reflects for you

Nar Sri
Level Up Coding
Published in
2 min readAug 24, 2023
Photo by Marc-Olivier Jodoin on Unsplash
class Story
end

obj = Story.new
obj.class # Story
obj.is_a? Story # true
obj = Story.new
obj.methods
obj.instance_variables

SomeModule.constants

Story.define_method(:clap) do |count|
puts "Successfully clapped #{count} times"
end
obj = Story.new
method = obj.method(:clap)
method.source_location # returns path to file with the method clap
class Story < ApplicationRecord
has_many :comments
end

# Using reflection to fetch associations
associations = Story.reflect_on_all_associations
associations.each do |association|
puts "Story associated with: #{association.name}"
end

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Written by Nar Sri

Experienced in Software | Writing on Tech, Productivity🌟

No responses yet

Write a response