My Reply
I like this a lot. It makes me want to go even harder:
user.sync_fully
user.sync_incrementally
You could do this a number of ways (TMTOWTDI)…
Hard-code the methods
class User
def sync(type, *rest)
# ...
end
def sync_fully(*rest) = sync :fully, *rest
def sync_incrementally(*rest) = sync :incrementally, *rest
end
Use method_missing
class User
def sync(type, *rest)
# ...
end
def method_missing(method_name, *rest)
super unless respond_to?(method_name)
sync(method_name[5..-1], *rest)
end
def respond_to_missing?(method_name, include_private = false)
method_name.start_with?("sync_")
end
end
Use Metaprogramming
class User
TYPES = %i[fully, incrementally]
def sync(type, *rest)
raise ArgumentError unless TYPES.include?(type)
# ...
end
TYPES.each do |type|
define_method("sync_#{type}") do |*rest|
sync(type, *rest)
end
end
end
5 Comments
@kerrick I'm curious… does your indieweb post on your site format my post/note's content if I use code fences with backticks?
“`ruby
puts 'this is a test'
“`
Remote Reply
Original Comment URL
Your Profile
@veganstraightedge @[email protected]
Looks like it doesn't. Oddly, it seems to think you want “
Remote Reply
Original Comment URL
Your Profile
@kerrick @[email protected] that's rude of it 😬
Are you using a Markdown parser on the post content? Is it Kramdown?
Remote Reply
Original Comment URL
Your Profile
@veganstraightedge @[email protected] It's actually just a WordPress blog with the Automattic's ActivityPub plugin [0]. The code in my post body is syntax highlighted by another plugin [1].
[0]: https://wordpress.org/plugins/activitypub/
[1]: https://wordpress.org/plugins/syntaxhighlighter/
Remote Reply
Original Comment URL
Your Profile
@kerrick @[email protected] ah, gotcha
bug report?
Reposts